#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9;
const ll infl = 1e18;
signed main() {
cin.tie(0)->sync_with_stdio(0);
string a, b;
cin >> a >> b;
string oa = a;
vector<vector<vector<vector<vector<ll>>>>> memo;
auto dp = [&](auto& dp, string& s, int i, char prev, char cur, bool free, int start)->ll{
if (i == (int)s.size()) return 1;
int n = s.size();
ll& key = memo[free][i][start][prev][cur];
if (key != -1) return key;
ll res = 0;
for (char c = '0'; c <= '9'; c++) {
if (c == prev && start <= i-2) continue;
if (c == cur && start <= i-1) continue;
if (free || c <= s[i]) {
res += dp(dp, s, i+1, cur, c, free || c < s[i], start == n && c != '0' ? i : start);
}
}
return key = res;
};
auto calc = [&](string s) {
if (s == "0") return 1ll;
memo = vector(2, vector(s.size(), vector(s.size()+1, vector(128, vector(128, -1ll)))));
return dp(dp, s, 0, '-', '-', false, s.size());
};
ll res = calc(b) - calc(a) + 1;
for (int i = 1; i < (int)a.size(); i++){
if (a[i] == a[i-1]) {res--; break; }
if (i >1 && a[i] == a[i-2]) {res--; break; }
}
cout << res << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5716 KB |
Output is correct |
2 |
Correct |
3 ms |
5716 KB |
Output is correct |
3 |
Runtime error |
77 ms |
131072 KB |
Execution killed with signal 9 |
4 |
Correct |
12 ms |
18116 KB |
Output is correct |
5 |
Correct |
2 ms |
3156 KB |
Output is correct |
6 |
Correct |
4 ms |
5716 KB |
Output is correct |
7 |
Correct |
4 ms |
5716 KB |
Output is correct |
8 |
Correct |
3 ms |
5672 KB |
Output is correct |
9 |
Correct |
2 ms |
4820 KB |
Output is correct |
10 |
Correct |
4 ms |
8916 KB |
Output is correct |
11 |
Correct |
13 ms |
21204 KB |
Output is correct |
12 |
Correct |
16 ms |
21160 KB |
Output is correct |
13 |
Correct |
5 ms |
8916 KB |
Output is correct |
14 |
Correct |
10 ms |
18180 KB |
Output is correct |
15 |
Correct |
14 ms |
18132 KB |
Output is correct |
16 |
Correct |
19 ms |
29284 KB |
Output is correct |
17 |
Correct |
25 ms |
29364 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Runtime error |
89 ms |
131072 KB |
Execution killed with signal 9 |
20 |
Correct |
11 ms |
18092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
61692 KB |
Output is correct |
2 |
Runtime error |
73 ms |
131072 KB |
Execution killed with signal 9 |
3 |
Runtime error |
74 ms |
131072 KB |
Execution killed with signal 9 |
4 |
Runtime error |
77 ms |
131072 KB |
Execution killed with signal 9 |
5 |
Correct |
20 ms |
32464 KB |
Output is correct |
6 |
Correct |
35 ms |
61652 KB |
Output is correct |
7 |
Correct |
17 ms |
28116 KB |
Output is correct |
8 |
Correct |
18 ms |
28152 KB |
Output is correct |
9 |
Correct |
16 ms |
23856 KB |
Output is correct |
10 |
Correct |
16 ms |
24016 KB |
Output is correct |
11 |
Correct |
43 ms |
61656 KB |
Output is correct |
12 |
Correct |
21 ms |
32364 KB |
Output is correct |
13 |
Correct |
22 ms |
28164 KB |
Output is correct |
14 |
Correct |
22 ms |
32332 KB |
Output is correct |
15 |
Correct |
19 ms |
30420 KB |
Output is correct |
16 |
Runtime error |
78 ms |
131072 KB |
Execution killed with signal 9 |
17 |
Runtime error |
83 ms |
131072 KB |
Execution killed with signal 9 |
18 |
Runtime error |
83 ms |
131072 KB |
Execution killed with signal 9 |
19 |
Runtime error |
89 ms |
131072 KB |
Execution killed with signal 9 |
20 |
Runtime error |
78 ms |
131072 KB |
Execution killed with signal 9 |
21 |
Runtime error |
82 ms |
131072 KB |
Execution killed with signal 9 |
22 |
Runtime error |
88 ms |
131072 KB |
Execution killed with signal 9 |
23 |
Runtime error |
85 ms |
131072 KB |
Execution killed with signal 9 |
24 |
Runtime error |
78 ms |
131072 KB |
Execution killed with signal 9 |
25 |
Runtime error |
76 ms |
131072 KB |
Execution killed with signal 9 |
26 |
Runtime error |
83 ms |
131072 KB |
Execution killed with signal 9 |
27 |
Runtime error |
76 ms |
131072 KB |
Execution killed with signal 9 |
28 |
Runtime error |
88 ms |
131072 KB |
Execution killed with signal 9 |
29 |
Runtime error |
74 ms |
131072 KB |
Execution killed with signal 9 |
30 |
Runtime error |
93 ms |
131072 KB |
Execution killed with signal 9 |
31 |
Runtime error |
84 ms |
131072 KB |
Execution killed with signal 9 |
32 |
Runtime error |
81 ms |
131072 KB |
Execution killed with signal 9 |
33 |
Runtime error |
85 ms |
131072 KB |
Execution killed with signal 9 |
34 |
Runtime error |
79 ms |
131072 KB |
Execution killed with signal 9 |
35 |
Runtime error |
89 ms |
131072 KB |
Execution killed with signal 9 |
36 |
Runtime error |
86 ms |
131072 KB |
Execution killed with signal 9 |
37 |
Runtime error |
75 ms |
131072 KB |
Execution killed with signal 9 |
38 |
Runtime error |
80 ms |
131072 KB |
Execution killed with signal 9 |
39 |
Runtime error |
78 ms |
131072 KB |
Execution killed with signal 9 |
40 |
Runtime error |
82 ms |
131072 KB |
Execution killed with signal 9 |
41 |
Runtime error |
78 ms |
131072 KB |
Execution killed with signal 9 |
42 |
Runtime error |
80 ms |
131072 KB |
Execution killed with signal 9 |
43 |
Runtime error |
81 ms |
131072 KB |
Execution killed with signal 9 |
44 |
Runtime error |
96 ms |
131072 KB |
Execution killed with signal 9 |
45 |
Runtime error |
96 ms |
131072 KB |
Execution killed with signal 9 |