#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;
char null = '0';
null--;
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-null][cur-null];
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(11, vector(11, -1ll)))));
return dp(dp, s, 0, null, null, 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 |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
2148 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
4 ms |
2132 KB |
Output is correct |
20 |
Correct |
0 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
852 KB |
Output is correct |
2 |
Correct |
6 ms |
2364 KB |
Output is correct |
3 |
Correct |
4 ms |
2260 KB |
Output is correct |
4 |
Correct |
4 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
852 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
4 ms |
2260 KB |
Output is correct |
17 |
Correct |
7 ms |
2260 KB |
Output is correct |
18 |
Correct |
4 ms |
2260 KB |
Output is correct |
19 |
Correct |
4 ms |
2260 KB |
Output is correct |
20 |
Correct |
4 ms |
2260 KB |
Output is correct |
21 |
Correct |
4 ms |
2260 KB |
Output is correct |
22 |
Correct |
4 ms |
2132 KB |
Output is correct |
23 |
Correct |
4 ms |
2260 KB |
Output is correct |
24 |
Correct |
4 ms |
2260 KB |
Output is correct |
25 |
Correct |
4 ms |
2260 KB |
Output is correct |
26 |
Correct |
4 ms |
2260 KB |
Output is correct |
27 |
Correct |
5 ms |
2260 KB |
Output is correct |
28 |
Correct |
5 ms |
2260 KB |
Output is correct |
29 |
Correct |
5 ms |
2452 KB |
Output is correct |
30 |
Correct |
4 ms |
2364 KB |
Output is correct |
31 |
Correct |
4 ms |
2260 KB |
Output is correct |
32 |
Correct |
4 ms |
2260 KB |
Output is correct |
33 |
Correct |
4 ms |
2132 KB |
Output is correct |
34 |
Correct |
4 ms |
2260 KB |
Output is correct |
35 |
Correct |
4 ms |
2260 KB |
Output is correct |
36 |
Correct |
4 ms |
2260 KB |
Output is correct |
37 |
Correct |
4 ms |
2132 KB |
Output is correct |
38 |
Correct |
6 ms |
2260 KB |
Output is correct |
39 |
Correct |
4 ms |
2260 KB |
Output is correct |
40 |
Correct |
4 ms |
2260 KB |
Output is correct |
41 |
Correct |
6 ms |
2260 KB |
Output is correct |
42 |
Correct |
4 ms |
2260 KB |
Output is correct |
43 |
Correct |
5 ms |
2320 KB |
Output is correct |
44 |
Correct |
4 ms |
2260 KB |
Output is correct |
45 |
Correct |
4 ms |
2260 KB |
Output is correct |