CSES - Putka Open 2020 – 3/5 - Results
Submission details
Task:Numerot
Sender:tykkipeli
Submission time:2020-10-18 04:48:34 +0300
Language:C++ (C++11)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED12
#2ACCEPTED13
#3ACCEPTED75
Test results
testverdicttimegroup
#1ACCEPTED0.02 s1, 2, 3details
#2ACCEPTED0.02 s2, 3details
#3ACCEPTED0.05 s3details

Compiler report

input/code.cpp:131:5: warning: "/*" within comment [-Wcomment]
     /*

Code

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
// a numeroa, käytössä b, eka numero c, vika numero d
pair<ll,int> dp[23][10][10][10];
bool done[23][10][10][10];
int maxdigit(ll n) {
int ans = 0;
while (n > 0) {
ans = max(ans,(int)(n%10));
n /= 10;
}
return ans;
}
pair<ll,int> solve(int a, int b, int c, int d) {
if (done[a][b][c][d]) return dp[a][b][c][d];
done[a][b][c][d] = true;
if (a == 1) {
dp[a][b][c][d] = {0,d};
return dp[a][b][c][d];
}
if (c == 1) {
if (a == 2) {
int val = 10 + d;
ll cnt = 0;
while (val >= 10) {
val -= max(b,maxdigit(val));
cnt++;
}
dp[a][b][c][d] = {cnt,val};
return dp[a][b][c][d];
} else {
if (b > d) {
auto p = solve(a-1, 9, 1, 10+d-b-1);
auto pp = solve(a-1, b, 9, p.second);
dp[a][b][c][d] = {p.first + pp.first, pp.second};
return dp[a][b][c][d];
} else {
int x = max(1,b);
auto p = solve(a-1, 9, 1, 10-x-1);
auto pp = solve(a-1, b, 9, p.second);
int lisa = 0;
if (d > 0) lisa++;
dp[a][b][c][d] = {p.first + pp.first + lisa , pp.second};
return dp[a][b][c][d];
}
}
} else {
int kaytossa = max(b,c);
if (b >= c || a == 2) {
auto p = solve(a,kaytossa,1,d);
auto pp = solve(a,b,c-1,p.second);
dp[a][b][c][d] = {p.first + pp.first, pp.second};
return dp[a][b][c][d];
} else {
// b < c kaytossa < eka merkki
if (c > d) {
auto p = solve(a, c-1, 1, d-1);
//if (a == 3 && b == 1 && c == 4 && d == 0) cout << p.first << " " << p.second << endl;
auto pp = solve(a, b, c-1, p.second);
//if (a == 3 && b == 1 && c == 4 && d == 0) cout << pp.first << " " << pp.second << endl;
dp[a][b][c][d] = {p.first + pp.first, pp.second};
return dp[a][b][c][d];
} else {
// b < c <= d
auto p = solve(a, b, c, 0);
dp[a][b][c][d] = {p.first + 1, p.second};
return dp[a][b][c][d];
}
}
}
}
ll ratkaise(ll x) {
ll ans = 0;
int digit = x%10;
int ind = 1;
while (x > 0) {
if (x%10 != 0) {
int maxi = maxdigit(x/10);
auto p = dp[ind][maxi][x%10][digit];
ans += p.first;
digit = p.second;
}
x /= 10;
ind++;
}
return ans+1;
}
void testCase() {
ll a;
cin >> a;
ll x = 0;
for (ll b = ULLONG_MAX; b >= 1; b /= 2) {
while (ratkaise(x+b) < a) x += b;
}
cout << x+1 << "\n";
}
//int lol[20000000];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
/*
for (int ind = 1; ind < 10000000; ind++) {
lol[ind] = 1 + lol[ind-maxdigit(ind)];
}
*/
for (int i = 1; i < 23; i++) {
for (int j = 0; j < 10; j++) {
for (int k = 1; k < 10; k++) {
for (int l = 0; l < 10; l++) {
solve(i,j,k,l);
}
}
}
}
int t;
cin >> t;
for (int i = 0; i < t; i++) {
testCase();
}
/*
/*
cout << dp[3][6][1][0].first << " " << dp[3][6][1][0].second << endl;
cout << endl;
for (int i = 1; i <= 9; i++) {
for (int j = 0; j <= 9; j++) {
cout << i << "0" << j << " " << dp[3][0][i][j].first+1 << endl;
}
}
*/
/*
for (int i = 1; i < 1000000; i++) {
cout << i << " " << ratkaise(i) << " " << lol[i] << endl;
if (ratkaise(i) != lol[i]) {
//cout << "VIRHE!" << endl;
cout << i << endl;
//break;
}
}
*/
//cout << dp[3][1][4][0].first << endl;
}

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: ACCEPTED

input
1000
627887018110416188
785474884983906653
653772166720939773
784335285960673683
...

correct output
5530371754830260284
6918696171534226533
5757755627065159149
6908439780325129803
3223801064342340738
...

user output
5530371754830260284
6918696171534226533
5757755627065159149
6908439780325129803
3223801064
...
Truncated