def dp(flag,prev,prev2,d):
if d==cur:
return 1
if dps[flag][prev][prev2][d] != -1:
return dps[flag][prev][prev2][d]
ans = 0
if flag:
for i in range(sus[d+1]+1):
if prev==10 and i==0: i = 10
if i==prev and i!=10: continue
if i==prev2 and i!=10: continue
if i==sus[d+1]:
ans += dp(1,i,prev,d+1)
else:
ans += dp(0,i,prev,d+1)
else:
for i in range(10):
if prev==10 and i==0: i = 10
if prev == i and i!=10: continue
if i==prev2 and i!=10: continue
ans += dp(0,i,prev,d+1)
dps[flag][prev][prev2][d] = ans
return ans
a,b = map(int, input().split())
sus = [-1]+[int(i) for i in str(a)]
cur = len(sus)-1
dps= [[[[-1 for i in range(19)]for i in range(11)]for i in range(11)]for i in range(2)]
aa = dp(1,10,10,0)
sus = [-1]+[int(i) for i in str(b)]
cur = len(sus)-1
dps= [[[[-1 for i in range(19)]for i in range(11)]for i in range(11)]for i in range(2)]
bb = dp(1,10,10,0)
sus = [int(i) for i in str(a)]
flag = True
for i in range(len(sus)-1):
if sus[i] == sus[i+1]:
flag = False
aa -= flag
print(bb-aa)
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
18856 KB |
Output is correct |
2 |
Correct |
37 ms |
18944 KB |
Output is correct |
3 |
Correct |
81 ms |
21776 KB |
Output is correct |
4 |
Correct |
50 ms |
19488 KB |
Output is correct |
5 |
Correct |
39 ms |
18956 KB |
Output is correct |
6 |
Correct |
38 ms |
18956 KB |
Output is correct |
7 |
Correct |
38 ms |
18856 KB |
Output is correct |
8 |
Correct |
39 ms |
18872 KB |
Output is correct |
9 |
Correct |
38 ms |
18928 KB |
Output is correct |
10 |
Correct |
38 ms |
18844 KB |
Output is correct |
11 |
Incorrect |
52 ms |
19984 KB |
Output isn't correct |
12 |
Correct |
71 ms |
19996 KB |
Output is correct |
13 |
Correct |
51 ms |
18872 KB |
Output is correct |
14 |
Correct |
49 ms |
19468 KB |
Output is correct |
15 |
Correct |
45 ms |
19496 KB |
Output is correct |
16 |
Correct |
62 ms |
21596 KB |
Output is correct |
17 |
Incorrect |
60 ms |
20560 KB |
Output isn't correct |
18 |
Correct |
39 ms |
18856 KB |
Output is correct |
19 |
Correct |
72 ms |
21632 KB |
Output is correct |
20 |
Correct |
51 ms |
19916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
21416 KB |
Output is correct |
2 |
Correct |
73 ms |
22024 KB |
Output is correct |
3 |
Correct |
67 ms |
21632 KB |
Output is correct |
4 |
Incorrect |
70 ms |
21704 KB |
Output isn't correct |
5 |
Correct |
64 ms |
20508 KB |
Output is correct |
6 |
Correct |
79 ms |
21364 KB |
Output is correct |
7 |
Correct |
68 ms |
20824 KB |
Output is correct |
8 |
Correct |
66 ms |
20824 KB |
Output is correct |
9 |
Correct |
53 ms |
20328 KB |
Output is correct |
10 |
Correct |
61 ms |
20400 KB |
Output is correct |
11 |
Correct |
64 ms |
21412 KB |
Output is correct |
12 |
Correct |
61 ms |
20624 KB |
Output is correct |
13 |
Correct |
58 ms |
20428 KB |
Output is correct |
14 |
Correct |
56 ms |
20492 KB |
Output is correct |
15 |
Incorrect |
64 ms |
20256 KB |
Output isn't correct |
16 |
Correct |
66 ms |
21544 KB |
Output is correct |
17 |
Correct |
67 ms |
21620 KB |
Output is correct |
18 |
Correct |
67 ms |
21544 KB |
Output is correct |
19 |
Correct |
71 ms |
21544 KB |
Output is correct |
20 |
Correct |
77 ms |
21776 KB |
Output is correct |
21 |
Correct |
67 ms |
21572 KB |
Output is correct |
22 |
Correct |
64 ms |
21808 KB |
Output is correct |
23 |
Correct |
66 ms |
21784 KB |
Output is correct |
24 |
Correct |
66 ms |
21628 KB |
Output is correct |
25 |
Correct |
67 ms |
21776 KB |
Output is correct |
26 |
Correct |
84 ms |
21600 KB |
Output is correct |
27 |
Correct |
92 ms |
21588 KB |
Output is correct |
28 |
Correct |
73 ms |
21724 KB |
Output is correct |
29 |
Correct |
67 ms |
21712 KB |
Output is correct |
30 |
Correct |
72 ms |
21560 KB |
Output is correct |
31 |
Correct |
70 ms |
21540 KB |
Output is correct |
32 |
Correct |
71 ms |
21644 KB |
Output is correct |
33 |
Correct |
65 ms |
21652 KB |
Output is correct |
34 |
Correct |
71 ms |
21544 KB |
Output is correct |
35 |
Correct |
74 ms |
21784 KB |
Output is correct |
36 |
Correct |
66 ms |
21640 KB |
Output is correct |
37 |
Correct |
63 ms |
21800 KB |
Output is correct |
38 |
Incorrect |
67 ms |
20636 KB |
Output isn't correct |
39 |
Incorrect |
73 ms |
21712 KB |
Output isn't correct |
40 |
Correct |
74 ms |
21704 KB |
Output is correct |
41 |
Correct |
79 ms |
21544 KB |
Output is correct |
42 |
Correct |
68 ms |
21656 KB |
Output is correct |
43 |
Correct |
66 ms |
21600 KB |
Output is correct |
44 |
Correct |
71 ms |
21756 KB |
Output is correct |
45 |
Correct |
71 ms |
21708 KB |
Output is correct |