#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 == 10 && p2 == 10) {
res += rec(pos+1, (i == 0 ? 10 : i), 10, (f || i < LIM));
}
else {
if(i == p1 || i == p2) 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) + mod) % mod << '\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;
| ~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
324 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 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
212 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 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 |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Incorrect |
1 ms |
324 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 |
328 KB |
Output isn't correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
36 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
37 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
38 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
39 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
40 |
Correct |
1 ms |
328 KB |
Output is correct |
41 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
44 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
45 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |