#include <bits/stdc++.h>
using namespace std;
long long f[20][2][2][20][10][10][2];
string a, b;
int n;
long long calc(int pos, bool ok1, bool ok2, int start, int prev, int prevPrev, bool check)
{
if (pos == n + 1) return !check;
if (f[pos][ok1][ok2][start][prev][prevPrev][check] != - 1) return f[pos][ok1][ok2][start][prev][prevPrev][check];
int low = 0, high = 9;
if (ok1) low = a[pos] - '0';
if (ok2) high = b[pos] - '0';
long long res = 0;
for (int i = low; i <= high; ++i)
{
bool okI = ok1 && i == a[pos] - '0', okII = ok2 && i == b[pos] - '0';
int first = (!start && i) ? pos : start;
bool okIII = check;
okIII |= start && i == prev;
okIII |= pos - start + 1 > 2 && i == prevPrev;
res += calc(pos + 1, okI, okII, first, i, prev, okIII);
}
return f[pos][ok1][ok2][start][prev][prevPrev][check] = res;
}
int main()
{
// freopen("test.inp", "r", stdin);
// freopen("test.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> a >> b;
while (a.size() < b.size()) a = "0" + a;
n = a.size();
a = "p" + a, b = "p" + b;
memset(f, - 1, sizeof(f));
cout << calc(1, 1, 1, 0, 0, 0, 0);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
3 |
Correct |
2 ms |
2816 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
5 |
Correct |
3 ms |
2944 KB |
Output is correct |
6 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
9 |
Correct |
2 ms |
2816 KB |
Output is correct |
10 |
Correct |
2 ms |
2816 KB |
Output is correct |
11 |
Correct |
2 ms |
2816 KB |
Output is correct |
12 |
Correct |
2 ms |
2816 KB |
Output is correct |
13 |
Correct |
2 ms |
2816 KB |
Output is correct |
14 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
16 |
Correct |
2 ms |
2816 KB |
Output is correct |
17 |
Correct |
2 ms |
2816 KB |
Output is correct |
18 |
Correct |
2 ms |
2816 KB |
Output is correct |
19 |
Correct |
2 ms |
2816 KB |
Output is correct |
20 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2816 KB |
Output is correct |
2 |
Correct |
2 ms |
2816 KB |
Output is correct |
3 |
Correct |
3 ms |
2816 KB |
Output is correct |
4 |
Correct |
3 ms |
2816 KB |
Output is correct |
5 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
6 |
Correct |
2 ms |
2816 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
2868 KB |
Output isn't correct |
9 |
Incorrect |
3 ms |
2816 KB |
Output isn't correct |
10 |
Incorrect |
3 ms |
2816 KB |
Output isn't correct |
11 |
Correct |
2 ms |
2816 KB |
Output is correct |
12 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
14 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
16 |
Correct |
2 ms |
2816 KB |
Output is correct |
17 |
Correct |
2 ms |
2816 KB |
Output is correct |
18 |
Correct |
2 ms |
2816 KB |
Output is correct |
19 |
Correct |
2 ms |
2816 KB |
Output is correct |
20 |
Correct |
2 ms |
2816 KB |
Output is correct |
21 |
Correct |
2 ms |
2816 KB |
Output is correct |
22 |
Correct |
2 ms |
2816 KB |
Output is correct |
23 |
Correct |
2 ms |
2816 KB |
Output is correct |
24 |
Correct |
2 ms |
2816 KB |
Output is correct |
25 |
Correct |
3 ms |
2816 KB |
Output is correct |
26 |
Correct |
3 ms |
2816 KB |
Output is correct |
27 |
Correct |
2 ms |
2816 KB |
Output is correct |
28 |
Correct |
2 ms |
2832 KB |
Output is correct |
29 |
Correct |
2 ms |
2816 KB |
Output is correct |
30 |
Correct |
2 ms |
2816 KB |
Output is correct |
31 |
Correct |
2 ms |
2816 KB |
Output is correct |
32 |
Correct |
2 ms |
2816 KB |
Output is correct |
33 |
Correct |
2 ms |
2816 KB |
Output is correct |
34 |
Correct |
2 ms |
2816 KB |
Output is correct |
35 |
Correct |
2 ms |
2816 KB |
Output is correct |
36 |
Correct |
2 ms |
2816 KB |
Output is correct |
37 |
Correct |
3 ms |
2816 KB |
Output is correct |
38 |
Correct |
2 ms |
2816 KB |
Output is correct |
39 |
Correct |
2 ms |
2816 KB |
Output is correct |
40 |
Correct |
2 ms |
2816 KB |
Output is correct |
41 |
Correct |
2 ms |
2816 KB |
Output is correct |
42 |
Correct |
2 ms |
2816 KB |
Output is correct |
43 |
Correct |
3 ms |
2816 KB |
Output is correct |
44 |
Correct |
2 ms |
2816 KB |
Output is correct |
45 |
Correct |
2 ms |
2816 KB |
Output is correct |