Task: | Numerot |
Sender: | tykkipeli |
Submission time: | 2020-10-18 03:47:34 +0300 |
Language: | Python3 (CPython3) |
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.69 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.72 s | 2, 3 | details |
#3 | TIME LIMIT EXCEEDED | -- | 3 | details |
Code
dp = [[[[(0,0)]*11 for i in range(11)] for k in range(11)] for j in range(30)] done = [[[[False]*11 for i in range(11)] for k in range(11)] for j in range(30)] def maxdigit(n): ans = 0 while n > 0: ans = max(ans, n%10) n //= 10 return ans def solve(a,b,c,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: val = 10+d cnt = 0 while val >= 10: val -= max(b,maxdigit(val)) cnt += 1 dp[a][b][c][d] = (cnt,val) return dp[a][b][c][d] else : if b > d: p = solve(a-1,9,1,10+d-b-1) pp = solve(a-1,b,9,p[1]) dp[a][b][c][d] = (p[0] + pp[0], pp[1]) return dp[a][b][c][d] else: x = max(1,b) p = solve(a-1,9,1,10-x-1) pp = solve(a-1,b,9,p[1]) lisa = 0 if d > 0: lisa += 1 dp[a][b][c][d] = (p[0] + pp[0] + lisa, pp[1]) return dp[a][b][c][d] else: kaytossa = max(b,c) if b >= c or a == 2: p = solve(a,kaytossa,1,d) pp = solve(a,b,c-1,p[1]) dp[a][b][c][d] = (p[0] + pp[0], pp[1]) return dp[a][b][c][d] else: if c > d: p = solve(a,c-1,1,d-1) pp = solve(a,b,c-1,p[1]) dp[a][b][c][d] = (p[0] + pp[0], pp[1]) return dp[a][b][c][d] else: p = solve(a,b,c,0) dp[a][b][c][d] = (p[0] + 1, p[1]) return dp[a][b][c][d] def ratkaise(y): n = len(y) x = [0]*n for i in range(n): x[i] = ord(y[i])-ord('0') prefmax = [0]*(n+1) prefmax[0] = x[0] i = 1 while i < n: prefmax[i] = max(prefmax[i-1], x[i]) i += 1 ans = 0 digit = x[n-1] ind = 1 i = n-1 while i >= 0: numero = x[i] if numero != 0: maxi = 0 if i > 0: maxi = prefmax[i-1] p = dp[ind][maxi][numero][digit] ans += p[0] digit = p[1] ind += 1 i -= 1 return ans + 1 for i in range(1,23): for j in range(10): for k in range(1,10): for l in range(10): solve(i,j,k,l) t = int(input()) for i in range(t): a = int(input()) x = 0 for i in range(67,-1,-1): if ratkaise(str(x+(1<<i))) < a: x |= (1<<i) print(x+1)
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) |