#include <bits/stdc++.h>
using namespace std;
int v[20];
int64_t f[20][2][2][11][11];
int64_t DP(int i, int lo, int iz, int prv, int prv2) {
if (i == 20) return 1;
int64_t& res = f[i][lo][iz][prv + 1][prv2 + 1];
if (lo && res != -1) return res;
int lim = lo ? 9 : v[i];
int64_t ans = 0;
for (int d = 0; d <= lim; d++) {
int niz = iz || (d > 0);
if (d != prv2 && d != prv) ans += DP(i + 1, lo || (d < lim), niz, niz ? d : -1, prv);
}
if (!lo) res = ans;
return ans;
}
int64_t solve(int64_t x) {
for (int i = 19; i >= 0; i--) v[i] = x % 10, x /= 10;
return DP(0, 0, 0, -1, -1);
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int64_t a, b;
cin >> a >> b;
a--;
memset(f, -1, sizeof f);
cout << solve(b) - solve(a);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Execution timed out |
1089 ms |
324 KB |
Time limit exceeded |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
372 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
324 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Execution timed out |
1081 ms |
328 KB |
Time limit exceeded |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
294 ms |
372 KB |
Output is correct |
2 |
Execution timed out |
1079 ms |
340 KB |
Time limit exceeded |
3 |
Execution timed out |
1084 ms |
340 KB |
Time limit exceeded |
4 |
Execution timed out |
1079 ms |
340 KB |
Time limit exceeded |
5 |
Correct |
92 ms |
324 KB |
Output is correct |
6 |
Correct |
355 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
340 KB |
Output is correct |
8 |
Correct |
4 ms |
320 KB |
Output is correct |
9 |
Correct |
7 ms |
340 KB |
Output is correct |
10 |
Correct |
9 ms |
324 KB |
Output is correct |
11 |
Correct |
262 ms |
376 KB |
Output is correct |
12 |
Correct |
57 ms |
376 KB |
Output is correct |
13 |
Correct |
15 ms |
396 KB |
Output is correct |
14 |
Correct |
92 ms |
320 KB |
Output is correct |
15 |
Correct |
106 ms |
380 KB |
Output is correct |
16 |
Execution timed out |
1071 ms |
340 KB |
Time limit exceeded |
17 |
Execution timed out |
1082 ms |
340 KB |
Time limit exceeded |
18 |
Execution timed out |
1074 ms |
340 KB |
Time limit exceeded |
19 |
Execution timed out |
1079 ms |
324 KB |
Time limit exceeded |
20 |
Execution timed out |
1070 ms |
340 KB |
Time limit exceeded |
21 |
Execution timed out |
1076 ms |
340 KB |
Time limit exceeded |
22 |
Execution timed out |
1079 ms |
340 KB |
Time limit exceeded |
23 |
Execution timed out |
1077 ms |
340 KB |
Time limit exceeded |
24 |
Execution timed out |
1073 ms |
340 KB |
Time limit exceeded |
25 |
Execution timed out |
1075 ms |
340 KB |
Time limit exceeded |
26 |
Execution timed out |
1063 ms |
340 KB |
Time limit exceeded |
27 |
Execution timed out |
1084 ms |
340 KB |
Time limit exceeded |
28 |
Execution timed out |
1073 ms |
340 KB |
Time limit exceeded |
29 |
Execution timed out |
1083 ms |
340 KB |
Time limit exceeded |
30 |
Execution timed out |
1075 ms |
340 KB |
Time limit exceeded |
31 |
Execution timed out |
1069 ms |
340 KB |
Time limit exceeded |
32 |
Execution timed out |
1033 ms |
340 KB |
Time limit exceeded |
33 |
Execution timed out |
1081 ms |
340 KB |
Time limit exceeded |
34 |
Execution timed out |
1076 ms |
340 KB |
Time limit exceeded |
35 |
Execution timed out |
1092 ms |
340 KB |
Time limit exceeded |
36 |
Execution timed out |
1077 ms |
340 KB |
Time limit exceeded |
37 |
Execution timed out |
1050 ms |
340 KB |
Time limit exceeded |
38 |
Execution timed out |
1088 ms |
340 KB |
Time limit exceeded |
39 |
Execution timed out |
1069 ms |
340 KB |
Time limit exceeded |
40 |
Execution timed out |
1063 ms |
340 KB |
Time limit exceeded |
41 |
Execution timed out |
1081 ms |
340 KB |
Time limit exceeded |
42 |
Execution timed out |
1078 ms |
340 KB |
Time limit exceeded |
43 |
Execution timed out |
1070 ms |
332 KB |
Time limit exceeded |
44 |
Execution timed out |
1069 ms |
340 KB |
Time limit exceeded |
45 |
Execution timed out |
1077 ms |
340 KB |
Time limit exceeded |