#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
ll dp[20][11][11][2][2][2];
string A, B;
ll f(int pos, int a, int b, bool fa, bool fb, bool start) {
if(pos == B.size()) return 1;
ll &ret = dp[pos][a][b][fa][fb][start];
if(~ret) return ret;
ret = 0;
int l = 0, r = 9;
if(!fa) l = A[pos] - '0';
if(!fb) r = B[pos] - '0';
for(int i = l; i <= r; i++) {
if(i == a || i == b) continue;
if(!i && start) {
ret += f(pos + 1, 10, 10, fa | (i > l), fb | (i < r), 1);
} else {
ret += f(pos + 1, b, i, fa | (i > l), fb | (i < r), 0);
}
} return ret;
}
int main(int argc, char const *argv[]) {
ll a, b;
scanf("%lld %lld", &a, &b);
A = to_string(a);
B = to_string(b);
while(A.size() < B.size()) A = "0" + A;
memset(dp, -1, sizeof dp);
printf("%lld\n", f(0, 10, 10, 0, 0, 1));
}
Compilation message
numbers.cpp: In function 'll f(int, int, int, bool, bool, bool)':
numbers.cpp:11:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(pos == B.size()) return 1;
~~~~^~~~~~~~~~~
numbers.cpp: In function 'int main(int, const char**)':
numbers.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &a, &b);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
648 KB |
Output is correct |
4 |
Correct |
3 ms |
648 KB |
Output is correct |
5 |
Correct |
3 ms |
676 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
3 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
748 KB |
Output is correct |
10 |
Correct |
3 ms |
748 KB |
Output is correct |
11 |
Correct |
3 ms |
748 KB |
Output is correct |
12 |
Correct |
3 ms |
748 KB |
Output is correct |
13 |
Correct |
2 ms |
748 KB |
Output is correct |
14 |
Correct |
2 ms |
748 KB |
Output is correct |
15 |
Correct |
5 ms |
748 KB |
Output is correct |
16 |
Correct |
3 ms |
748 KB |
Output is correct |
17 |
Correct |
3 ms |
748 KB |
Output is correct |
18 |
Correct |
3 ms |
748 KB |
Output is correct |
19 |
Correct |
3 ms |
748 KB |
Output is correct |
20 |
Correct |
3 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
748 KB |
Output is correct |
2 |
Correct |
3 ms |
748 KB |
Output is correct |
3 |
Correct |
4 ms |
748 KB |
Output is correct |
4 |
Correct |
2 ms |
748 KB |
Output is correct |
5 |
Correct |
2 ms |
748 KB |
Output is correct |
6 |
Correct |
0 ms |
748 KB |
Output is correct |
7 |
Correct |
3 ms |
748 KB |
Output is correct |
8 |
Correct |
1 ms |
748 KB |
Output is correct |
9 |
Correct |
3 ms |
748 KB |
Output is correct |
10 |
Correct |
5 ms |
748 KB |
Output is correct |
11 |
Correct |
3 ms |
748 KB |
Output is correct |
12 |
Correct |
3 ms |
748 KB |
Output is correct |
13 |
Correct |
2 ms |
748 KB |
Output is correct |
14 |
Correct |
5 ms |
748 KB |
Output is correct |
15 |
Correct |
4 ms |
748 KB |
Output is correct |
16 |
Correct |
2 ms |
748 KB |
Output is correct |
17 |
Correct |
3 ms |
748 KB |
Output is correct |
18 |
Correct |
3 ms |
748 KB |
Output is correct |
19 |
Correct |
4 ms |
752 KB |
Output is correct |
20 |
Correct |
3 ms |
752 KB |
Output is correct |
21 |
Correct |
4 ms |
752 KB |
Output is correct |
22 |
Correct |
3 ms |
752 KB |
Output is correct |
23 |
Correct |
3 ms |
752 KB |
Output is correct |
24 |
Correct |
2 ms |
752 KB |
Output is correct |
25 |
Correct |
3 ms |
752 KB |
Output is correct |
26 |
Correct |
3 ms |
752 KB |
Output is correct |
27 |
Correct |
3 ms |
752 KB |
Output is correct |
28 |
Correct |
3 ms |
752 KB |
Output is correct |
29 |
Correct |
3 ms |
752 KB |
Output is correct |
30 |
Correct |
4 ms |
752 KB |
Output is correct |
31 |
Correct |
3 ms |
752 KB |
Output is correct |
32 |
Correct |
2 ms |
752 KB |
Output is correct |
33 |
Correct |
3 ms |
752 KB |
Output is correct |
34 |
Correct |
3 ms |
752 KB |
Output is correct |
35 |
Correct |
3 ms |
752 KB |
Output is correct |
36 |
Correct |
4 ms |
764 KB |
Output is correct |
37 |
Correct |
3 ms |
764 KB |
Output is correct |
38 |
Correct |
3 ms |
764 KB |
Output is correct |
39 |
Correct |
3 ms |
764 KB |
Output is correct |
40 |
Correct |
3 ms |
764 KB |
Output is correct |
41 |
Correct |
3 ms |
768 KB |
Output is correct |
42 |
Correct |
3 ms |
768 KB |
Output is correct |
43 |
Correct |
2 ms |
868 KB |
Output is correct |
44 |
Correct |
3 ms |
868 KB |
Output is correct |
45 |
Correct |
4 ms |
868 KB |
Output is correct |