#include <bits/stdc++.h>
using namespace std;
long long dp[20][2][2][10][10];
string a, b;
long long solve (int pos, bool low, bool high, int last, int prevlast, bool nonzero) {
if (pos == a.length()) return 1;
long long &ans = dp[pos][low][high][last][prevlast];
if (ans != -1) return ans;
ans = 0;
int l = 0, r = 9;
if (low) l = a[pos] - '0';
if (high) r = b[pos] - '0';
for (int i = l; i <= r; i++) {
bool newlow = 0;
bool newhigh = 0;
if (low && i == l) newlow = 1;
if (high && i == r) newhigh = 1;
if (!nonzero) {
if (i == 0) ans += solve(pos + 1, newlow, newhigh, last, prevlast, nonzero);
else if (i != last && i != prevlast) ans += solve(pos + 1, newlow, newhigh, i, last, true);
}
else if (i != last && i != prevlast) ans += solve(pos + 1, newlow, newhigh, i, last, true);
}
return ans;
}
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> a >> b;
while (a.length() < b.length()) a = "0" + a;
while (b.length() < a.length()) b = "0" + b;
memset(dp, -1, sizeof(dp));
cout << solve(0, 1, 1, -1, -1, 0);
return 0;
}
Compilation message
numbers.cpp: In function 'long long int solve(int, bool, bool, int, int, bool)':
numbers.cpp:9:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (pos == a.length()) return 1;
~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
544 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Incorrect |
2 ms |
592 KB |
Output isn't correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
696 KB |
Output is correct |
7 |
Correct |
2 ms |
696 KB |
Output is correct |
8 |
Correct |
2 ms |
696 KB |
Output is correct |
9 |
Correct |
2 ms |
696 KB |
Output is correct |
10 |
Correct |
2 ms |
696 KB |
Output is correct |
11 |
Correct |
2 ms |
696 KB |
Output is correct |
12 |
Correct |
2 ms |
696 KB |
Output is correct |
13 |
Correct |
3 ms |
696 KB |
Output is correct |
14 |
Incorrect |
2 ms |
696 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
696 KB |
Output isn't correct |
16 |
Correct |
2 ms |
696 KB |
Output is correct |
17 |
Correct |
2 ms |
700 KB |
Output is correct |
18 |
Correct |
2 ms |
704 KB |
Output is correct |
19 |
Correct |
2 ms |
768 KB |
Output is correct |
20 |
Incorrect |
2 ms |
768 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
2 ms |
768 KB |
Output is correct |
3 |
Correct |
2 ms |
768 KB |
Output is correct |
4 |
Correct |
2 ms |
768 KB |
Output is correct |
5 |
Incorrect |
2 ms |
768 KB |
Output isn't correct |
6 |
Correct |
2 ms |
768 KB |
Output is correct |
7 |
Incorrect |
2 ms |
768 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
768 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
808 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
864 KB |
Output isn't correct |
11 |
Correct |
2 ms |
864 KB |
Output is correct |
12 |
Incorrect |
2 ms |
864 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
864 KB |
Output isn't correct |
14 |
Incorrect |
2 ms |
864 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
864 KB |
Output isn't correct |
16 |
Correct |
2 ms |
864 KB |
Output is correct |
17 |
Correct |
2 ms |
864 KB |
Output is correct |
18 |
Correct |
2 ms |
864 KB |
Output is correct |
19 |
Correct |
2 ms |
864 KB |
Output is correct |
20 |
Correct |
2 ms |
864 KB |
Output is correct |
21 |
Correct |
2 ms |
864 KB |
Output is correct |
22 |
Correct |
2 ms |
864 KB |
Output is correct |
23 |
Correct |
2 ms |
872 KB |
Output is correct |
24 |
Correct |
2 ms |
940 KB |
Output is correct |
25 |
Correct |
2 ms |
940 KB |
Output is correct |
26 |
Correct |
2 ms |
940 KB |
Output is correct |
27 |
Correct |
2 ms |
940 KB |
Output is correct |
28 |
Correct |
2 ms |
940 KB |
Output is correct |
29 |
Correct |
2 ms |
964 KB |
Output is correct |
30 |
Correct |
2 ms |
964 KB |
Output is correct |
31 |
Correct |
2 ms |
964 KB |
Output is correct |
32 |
Correct |
2 ms |
964 KB |
Output is correct |
33 |
Correct |
2 ms |
964 KB |
Output is correct |
34 |
Correct |
2 ms |
964 KB |
Output is correct |
35 |
Correct |
2 ms |
964 KB |
Output is correct |
36 |
Correct |
2 ms |
964 KB |
Output is correct |
37 |
Correct |
2 ms |
964 KB |
Output is correct |
38 |
Correct |
2 ms |
964 KB |
Output is correct |
39 |
Correct |
2 ms |
964 KB |
Output is correct |
40 |
Correct |
2 ms |
964 KB |
Output is correct |
41 |
Correct |
2 ms |
964 KB |
Output is correct |
42 |
Correct |
2 ms |
964 KB |
Output is correct |
43 |
Correct |
2 ms |
1008 KB |
Output is correct |
44 |
Correct |
2 ms |
1008 KB |
Output is correct |
45 |
Correct |
2 ms |
1008 KB |
Output is correct |