#include <bits/stdc++.h>
using namespace std;
string num;
int dp[19][11][11][2];
int mod = 1e9 + 7;
int rec(int pos, int p1, int p2, int f) {
if(pos == num.size()) return 1;
if(dp[pos][p1][p2][f] != -1) return dp[pos][p1][p2][f];
int LIM = 9;
if(!f) LIM = num[pos] - '0';
int res = 0;
for (int i = 0; i<=LIM; i++) {
if(p1 == i || p2 == i) continue;
res += rec(pos+1, i, p1, (f || i < LIM));
if(res >= mod) res -= mod;
}
return dp[pos][p1][p2][f] = res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long A, B;
cin >> A >> B;
num = to_string(B);
if(A == 0) {
memset(dp, -1 ,sizeof(dp));
cout << rec(0, 10, 10, 0) << '\n';
}
else {
A--;
memset(dp, -1 ,sizeof(dp));
B = rec(0, 10, 10, 0);
memset(dp, -1, sizeof(dp)); num = to_string(A);
cout << B - rec(0, 10, 10, 0) << '\n';
}
return 0;
}
Compilation message
numbers.cpp: In function 'int rec(int, int, int, int)':
numbers.cpp:13:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | if(pos == num.size()) return 1;
| ~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Correct |
0 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Incorrect |
2 ms |
212 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
16 |
Correct |
1 ms |
328 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
328 KB |
Output is correct |
31 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
32 |
Correct |
1 ms |
328 KB |
Output is correct |
33 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
34 |
Correct |
1 ms |
324 KB |
Output is correct |
35 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
36 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
37 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
38 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
39 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
44 |
Incorrect |
1 ms |
220 KB |
Output isn't correct |
45 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |