CSES - Putka Open 2020 – 3/5 - Results
Submission details
Task:Numerot
Sender:Sisuaski
Submission time:2020-10-17 09:46:57 +0300
Language:C++17
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED12
#2ACCEPTED13
#3ACCEPTED75
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#2ACCEPTED0.05 s2, 3details
#3ACCEPTED0.72 s3details

Code

#include <iostream>
#include <unordered_map>
using namespace std;
typedef unsigned long long ull;
typedef pair<ull, int> P;

unordered_map<ull, P> M[10];

P f(unsigned k, ull n) {
	if (n==0 && k==0) return {0, 0};
	if (n<=k) return {1, k-n};
	if (n<10) return {1, 0};
	auto& dp = M[k][n];
	if (dp.first > 0) return dp;
	ull g=1;
	for(; g<=n/10; g*=10);
	ull res=0;
	while(1) {
		unsigned a = n/g;
		P p = f(max(k,a), n%g);
		res += p.first;
		if (a==0) return dp = {res, p.second};
		n = a*g - p.second;
		if (p.second == 0) {
			n -= max(a,k);
			res++;
		}
	}
}

int main() {
	int t;cin>>t;
	while(t--){
		ull x;cin>>x;
		ull low=x-1, hi=9*x;
		while(hi-low>1) {
			ull mid = low+(hi-low)/2;
			if (f(0,mid).first < x) low=mid;
			else hi=mid;
		}
		cout<<hi<<'\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
...

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
...

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
3223801064342340738
...