#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, bool zeros)->ll{
if (i == (int)s.size()) return 1;
ll& key = memo[free][zeros][i][prev][cur];
if (key != -1) return key;
ll res = 0;
for (char c = '0'; c <= '9'; c++) {
if (c == prev || c == cur) {
if (!(zeros && c == '0'))
continue;
}
if (free || c <= s[i]) {
res += dp(dp, s, i+1, cur, c, free || c < s[i], zeros && c > '0');
}
}
return key = res;
};
auto calc = [&](string s) {
if (s == "0") return 1ll;
memo = vector(2, vector(2, vector(s.size(), vector(128, vector(128, -1ll)))));
return dp(dp, s, 0, '-', '-', false, true);
};
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 |
Incorrect |
2 ms |
3156 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
3156 KB |
Output isn't correct |
3 |
Correct |
15 ms |
23804 KB |
Output is correct |
4 |
Incorrect |
3 ms |
5972 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
2388 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
3156 KB |
Output isn't correct |
7 |
Incorrect |
3 ms |
3144 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
3156 KB |
Output isn't correct |
9 |
Correct |
2 ms |
3284 KB |
Output is correct |
10 |
Correct |
3 ms |
4820 KB |
Output is correct |
11 |
Correct |
4 ms |
7764 KB |
Output is correct |
12 |
Correct |
4 ms |
7764 KB |
Output is correct |
13 |
Correct |
2 ms |
4820 KB |
Output is correct |
14 |
Incorrect |
3 ms |
5972 KB |
Output isn't correct |
15 |
Incorrect |
3 ms |
5936 KB |
Output isn't correct |
16 |
Correct |
5 ms |
9172 KB |
Output is correct |
17 |
Correct |
6 ms |
9172 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
15 ms |
23804 KB |
Output is correct |
20 |
Incorrect |
4 ms |
5972 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
13524 KB |
Output is correct |
2 |
Correct |
15 ms |
25372 KB |
Output is correct |
3 |
Correct |
15 ms |
25304 KB |
Output is correct |
4 |
Correct |
14 ms |
25300 KB |
Output is correct |
5 |
Incorrect |
6 ms |
9300 KB |
Output isn't correct |
6 |
Correct |
8 ms |
13524 KB |
Output is correct |
7 |
Incorrect |
5 ms |
8788 KB |
Output isn't correct |
8 |
Incorrect |
5 ms |
8788 KB |
Output isn't correct |
9 |
Incorrect |
4 ms |
6868 KB |
Output isn't correct |
10 |
Incorrect |
4 ms |
7892 KB |
Output isn't correct |
11 |
Correct |
8 ms |
13524 KB |
Output is correct |
12 |
Incorrect |
6 ms |
9300 KB |
Output isn't correct |
13 |
Incorrect |
5 ms |
8752 KB |
Output isn't correct |
14 |
Incorrect |
5 ms |
9300 KB |
Output isn't correct |
15 |
Incorrect |
5 ms |
8404 KB |
Output isn't correct |
16 |
Correct |
15 ms |
25300 KB |
Output is correct |
17 |
Correct |
18 ms |
25428 KB |
Output is correct |
18 |
Correct |
16 ms |
25272 KB |
Output is correct |
19 |
Correct |
16 ms |
25300 KB |
Output is correct |
20 |
Correct |
19 ms |
25428 KB |
Output is correct |
21 |
Correct |
16 ms |
25272 KB |
Output is correct |
22 |
Correct |
15 ms |
23900 KB |
Output is correct |
23 |
Correct |
16 ms |
25300 KB |
Output is correct |
24 |
Correct |
15 ms |
25300 KB |
Output is correct |
25 |
Correct |
15 ms |
25300 KB |
Output is correct |
26 |
Correct |
15 ms |
25276 KB |
Output is correct |
27 |
Correct |
17 ms |
25300 KB |
Output is correct |
28 |
Correct |
18 ms |
25352 KB |
Output is correct |
29 |
Correct |
17 ms |
25292 KB |
Output is correct |
30 |
Correct |
16 ms |
25300 KB |
Output is correct |
31 |
Correct |
16 ms |
25356 KB |
Output is correct |
32 |
Correct |
15 ms |
25296 KB |
Output is correct |
33 |
Correct |
16 ms |
23824 KB |
Output is correct |
34 |
Correct |
16 ms |
25344 KB |
Output is correct |
35 |
Correct |
17 ms |
25428 KB |
Output is correct |
36 |
Correct |
15 ms |
25300 KB |
Output is correct |
37 |
Correct |
19 ms |
23884 KB |
Output is correct |
38 |
Correct |
15 ms |
25300 KB |
Output is correct |
39 |
Correct |
16 ms |
25272 KB |
Output is correct |
40 |
Correct |
17 ms |
25300 KB |
Output is correct |
41 |
Correct |
19 ms |
25344 KB |
Output is correct |
42 |
Correct |
16 ms |
25300 KB |
Output is correct |
43 |
Correct |
16 ms |
25272 KB |
Output is correct |
44 |
Correct |
17 ms |
25256 KB |
Output is correct |
45 |
Correct |
15 ms |
25300 KB |
Output is correct |