#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int da[20];
int db[20];
ll memo[20][2][2][10][10][2][2];
ll solve(int idx, bool flagA, bool flagB, int pre1, int pre2, bool zero1, bool zero2) {
if (idx == -1) {
return 1;
}
if (memo[idx][flagA][flagB][pre1][pre2][zero1][zero2] != -1) {
return memo[idx][flagA][flagB][pre1][pre2][zero1][zero2];
}
ll rs = 0;
for (int d = 0; d <= 9; ++d) {
if (flagA && d < da[idx]) continue;
if (flagB && d > db[idx]) continue;
if ((!zero1 && pre1 == d) || (!zero2 && pre2 == d)) continue;
bool nzero1;
if (zero1 && d == 0) nzero1 = true;
else nzero1 = false;
rs += solve(idx - 1, flagA && d == da[idx], flagB && d == db[idx], d, pre1, nzero1, zero1);
}
return memo[idx][flagA][flagB][pre1][pre2][zero1][zero2] = rs;
}
int main() {
ll a, b;
cin >> a >> b;
fill(da, da + 20, 0);
fill(db, db + 20, 0);
for (int i = 0; i < 20; ++i) {
da[i] = a % 10;
db[i] = b % 10;
a /= 10; b /= 10;
}
fill(memo[0][0][0][0][0][0], memo[0][0][0][0][0][0] + 32000, -1);
cout << solve(19, true, true, 0, 0, true, true) << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
780 KB |
Output is correct |
3 |
Correct |
2 ms |
976 KB |
Output is correct |
4 |
Correct |
2 ms |
976 KB |
Output is correct |
5 |
Correct |
2 ms |
976 KB |
Output is correct |
6 |
Correct |
2 ms |
976 KB |
Output is correct |
7 |
Correct |
2 ms |
976 KB |
Output is correct |
8 |
Correct |
2 ms |
976 KB |
Output is correct |
9 |
Correct |
2 ms |
976 KB |
Output is correct |
10 |
Correct |
2 ms |
984 KB |
Output is correct |
11 |
Correct |
2 ms |
1008 KB |
Output is correct |
12 |
Correct |
2 ms |
1060 KB |
Output is correct |
13 |
Correct |
2 ms |
1060 KB |
Output is correct |
14 |
Correct |
2 ms |
1108 KB |
Output is correct |
15 |
Correct |
2 ms |
1108 KB |
Output is correct |
16 |
Correct |
2 ms |
1108 KB |
Output is correct |
17 |
Correct |
2 ms |
1108 KB |
Output is correct |
18 |
Correct |
2 ms |
1108 KB |
Output is correct |
19 |
Correct |
2 ms |
1108 KB |
Output is correct |
20 |
Correct |
2 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1108 KB |
Output is correct |
2 |
Correct |
2 ms |
1108 KB |
Output is correct |
3 |
Correct |
2 ms |
1108 KB |
Output is correct |
4 |
Correct |
3 ms |
1108 KB |
Output is correct |
5 |
Correct |
2 ms |
1108 KB |
Output is correct |
6 |
Correct |
2 ms |
1108 KB |
Output is correct |
7 |
Correct |
2 ms |
1108 KB |
Output is correct |
8 |
Correct |
2 ms |
1108 KB |
Output is correct |
9 |
Correct |
2 ms |
1108 KB |
Output is correct |
10 |
Correct |
2 ms |
1108 KB |
Output is correct |
11 |
Correct |
2 ms |
1108 KB |
Output is correct |
12 |
Correct |
2 ms |
1108 KB |
Output is correct |
13 |
Correct |
2 ms |
1108 KB |
Output is correct |
14 |
Correct |
2 ms |
1224 KB |
Output is correct |
15 |
Correct |
3 ms |
1224 KB |
Output is correct |
16 |
Correct |
2 ms |
1224 KB |
Output is correct |
17 |
Correct |
2 ms |
1224 KB |
Output is correct |
18 |
Correct |
2 ms |
1224 KB |
Output is correct |
19 |
Correct |
2 ms |
1224 KB |
Output is correct |
20 |
Correct |
2 ms |
1224 KB |
Output is correct |
21 |
Correct |
3 ms |
1224 KB |
Output is correct |
22 |
Correct |
2 ms |
1224 KB |
Output is correct |
23 |
Correct |
2 ms |
1224 KB |
Output is correct |
24 |
Correct |
2 ms |
1224 KB |
Output is correct |
25 |
Correct |
2 ms |
1224 KB |
Output is correct |
26 |
Correct |
2 ms |
1224 KB |
Output is correct |
27 |
Correct |
2 ms |
1224 KB |
Output is correct |
28 |
Correct |
2 ms |
1224 KB |
Output is correct |
29 |
Correct |
2 ms |
1224 KB |
Output is correct |
30 |
Correct |
2 ms |
1224 KB |
Output is correct |
31 |
Correct |
2 ms |
1224 KB |
Output is correct |
32 |
Correct |
2 ms |
1224 KB |
Output is correct |
33 |
Correct |
3 ms |
1224 KB |
Output is correct |
34 |
Correct |
2 ms |
1224 KB |
Output is correct |
35 |
Correct |
2 ms |
1224 KB |
Output is correct |
36 |
Correct |
2 ms |
1224 KB |
Output is correct |
37 |
Correct |
2 ms |
1232 KB |
Output is correct |
38 |
Correct |
2 ms |
1248 KB |
Output is correct |
39 |
Correct |
2 ms |
1260 KB |
Output is correct |
40 |
Correct |
2 ms |
1260 KB |
Output is correct |
41 |
Correct |
2 ms |
1260 KB |
Output is correct |
42 |
Correct |
2 ms |
1260 KB |
Output is correct |
43 |
Correct |
2 ms |
1264 KB |
Output is correct |
44 |
Correct |
2 ms |
1280 KB |
Output is correct |
45 |
Correct |
2 ms |
1280 KB |
Output is correct |