Task: | Numerot |
Sender: | Lieska |
Submission time: | 2020-10-18 21:01:53 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 25 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 12 |
#2 | ACCEPTED | 13 |
#3 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.02 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.09 s | 2, 3 | details |
#3 | TIME LIMIT EXCEEDED | -- | 3 | details |
Code
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll l[33][11], r[33][11][11], v[33][11][11], vas[111], ky[33], ysi[33], ra[33][11][11][11], va[33][11][11][11]; int x, x1; unsigned long long big = 9000000000000000000; map<ll, ll> ma; ll f(ll a){ int b=1; while ((a/ky[b])%10==9) b++; //cout << "tasa " << b << " " << ky[b] << " " << (a/ky[b]) << " " << (a/ky[b])%10 << " " << a <<"\n"; x1=(a/ky[b])%10; int c=0; for (int i=max(b+1,2); i<=18; ++i){ c = max(c, (int)(a/ky[i])%10); } x=c; return b; } ll askeleet(ll a){ //cout << a << " a\n"; if (ma[a]) return ma[a]; if (a<100){ return vas[a]; } ll a1=a; ll a2=f(a); ll c=a%(100), ans=0; if (a2>2) x=9; if (a2==2) x=max(x, x1); //cout << a << " " << x << " " << x1 << " " << ans << " " << c << " " << a2 << "\n"; 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; //cout << a << " " << viim << " " << ans << "\n"; while (true){ ll b=f(a); if (x==0 && x1==0) break; ans = ans + r[b][max(x1,x)][viim]; a = (a/ky[b]-1)*ky[b] + ysi[b] + v[b][max(x,x1)][viim]; viim=a%10; /* else{ ans = ans + ra[b][x][x1][viim]; a = (a/ky[b+1]-1)*ky[b+1] + ysi[b+1] + va[b][x][x1][viim]; viim=a%10; } */ //cout << a << " " << b << " " << x << " " << x1 << " " << ans << " " << viim << " " << ysi[b] << " " << v[b][x1][viim] << " \n"; } //cout << a << " " << viim << " " << ans << "\n"; ll b=f(a); ans+=l[b][viim]; //cout << a << " " << b << " " << viim << " " << l[b][viim] << " " << ans << "\n"; ma[a1]=ans; return ans; } int main(){ int t; cin >> t; ky[0]=1; ysi[2]=90; for (int i=1; i<=18; ++i) ky[i]=ky[i-1]*10; for (int i=3; i<=18; ++i) ysi[i] = 9*ky[i-1]+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<=18; ++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<=18; ++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; } } for (int i=2; i<=18; ++i){ for (int k=1; k<=9; ++k){ for (int l=0; l<=8; ++l){ if (k==0 && l==0) continue; for (int j=1; j<=9; ++j){ ll a=0, b=j; for (int m=l; m>=0; --m){ a+=r[i][max(k, m)][b]; b =v[i][max(k, m)][b]; } ra[i][k][l][j]=a; va[i][k][l][j]=b; } } } } while (t--){ ll y; cin >> y; if (y==1) { cout << "1\n"; continue; } ll a=1; while (true){ unsigned long long a1=(unsigned long long)a*2; if (a1>big) break; if (askeleet(a*2)>=y) break; a=a*2; //cout << a << " " << a1 << "\n"; } ll b=a; //cout << a << " " << b << "\n"; while (a>=1){ unsigned long long a1=(unsigned long long)(b + a); if (a1<big){ if (askeleet(b+a)<y) b = b+a; } a/=2; //cout << a << " " << b << "\n"; } cout << b+1 << "\n"; } }
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1000 1 2 3 4 ... |
correct output |
---|
1 10 11 20 22 ... |
user output |
---|
1 10 11 20 22 ... Truncated |
Test 2
Group: 2, 3
Verdict: ACCEPTED
input |
---|
1000 224995 413660 249827 2125 ... |
correct output |
---|
1731724 3216040 1940719 14585 532612 ... |
user output |
---|
1731724 3216040 1940719 14585 532612 ... Truncated |
Test 3
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000 627887018110416188 785474884983906653 653772166720939773 784335285960673683 ... |
correct output |
---|
5530371754830260284 6918696171534226533 5757755627065159149 6908439780325129803 3223801064342340738 ... |
user output |
---|
(empty) |