CSES - Putka Open 2020 – 3/5 - Results
Submission details
Task:Numerot
Sender:Lieska
Submission time:2020-10-18 17:06:23 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:105:13: error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' and 'll {aka __int128}')
         cin >> y;
         ~~~~^~~~
In file included from /usr/include/c++/7/sstream:38:0,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from input/code.cpp:1:
/usr/include/c++/7/istream:120:7: note: candidate: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__istream_type& (*)(std::basic_istream<_CharT, _Traits>::__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>] <near match>
       operator>>(__istream_type& (*__pf)(__istream_type&))
       ^~~~~~~~
/usr/inc...

Code

#include <bits/stdc++.h>
using namespace std;

typedef __int128_t ll;


ll l[22][10], r[22][10][10], v[22][10][10], vas[111], ky[22], ysi[22];
int x;

ll f(ll a){
    int b=0;
    while ((a/ky[b+1])%10==9) b++;
    int c=0;
    for (int i=max(b+1,2); i<=20; ++i){
        c = max(c, (int)(a/ky[i])%10);
    }
    x=c;
    return b;
}

ll askeleet(ll a){
    if (a<100){
        return vas[a];
    }
    ll c=f(a), ans=0;
    if (c==0){
        ll c=a%(100);
        while (c>=0){
            int d=c%10, e=(c/10)%10;
            c = c - max(x, max(d, e));
            ans++;
        }
        a = (a/100)*100 + c;
    }
    int viim=a%10;
    while (true){
        ll b=f(a);
        if (x==0) break;
        ans = ans + r[b+1][x][viim];
        a = (a/ky[b+1]-1)*ky[b+1] + ysi[b] + v[b+1][x][viim];
        viim=a%10;
    }
    ll b=f(a);
    ans+=l[b+1][viim];
    return ans;
}


int main(){
    int t;
    cin >> t;
    ky[0]=1;
    ysi[1]=90;
    for (int i=1; i<=20; ++i) ky[i]=ky[i-1]*10;
    for (int i=2; i<=20; ++i) ysi[i] = 9*ky[i]+ysi[i-1];
    for (int i=1; i<=100; ++i){
        int a=0;
        a = max(a, i%10);
        a = max(a, (i/10)%10);
        vas[i]=vas[i-a]+1;
    }
    l[2][1]=l[2][2]=l[2][3]=15;
    for (int i=4; i<=9; ++i) l[2][i]=16;
    for (int k=1; k<=9; ++k){
        for (int j=1; j<=9; ++j){
            int a=90+j;
            int b=0;
            while (a>=0){
                int d=a%10, e=(a/10)%10;
                a = a - max(k, max(d, e));
                b++;
            }
            a+=10;
            r[2][k][j]=b;
            v[2][k][j]=a;
        }
    }
    for (int i=3; i<=20; ++i){
        for (int k=1; k<=9; ++k){
            for (int j=1; j<=9; ++j){
                ll a=0, b=j;
                for (int m=9; m>=0; --m){
                    int c=max(k, m);
                    a+=r[i-1][c][b];
                    b = v[i-1][c][b];
                }
                r[i][k][j]=a;
                v[i][k][j]=b;
            }
        }
    }
    for (int i=3; i<=20; ++i){
        for (int j=1; j<=9; ++j){
            ll a=0, b=j;
            for (int m=9; m>=1; --m){
                a+=r[i-1][m][b];
                b=v[i-1][m][b];
            }
            a+=l[i-1][b];
            l[i][j]=a;
        }
    }
    while (t--){
        ll y;
        cin >> y;
        if (y==1) {
            cout << "1\n";
            continue;
        }
        ll a=1;
        while (askeleet(a*2)<y){
            a*=2;
        }
        ll b=a;
        while (a>=1){
            if (askeleet(b+a)<y) b = b+a;
            a/=2;
        }
        ll b1=(b+1)/100, b2=(b+1)%100;
        if (b1!=0) cout << (long long)b1;
        cout << (long long)b2 << "\n";
    }
}