#include <bits/stdc++.h>
using namespace std;
long long a, b, ans;
long long f[20][15][15][2][2];
char A[20];
long long solve(int pos, int a, int b, int fs, int st) {
if(!A[pos]) return 1LL;
long long &ret = f[pos][a][b][fs][st];
if(~ret) return ret;
ret = 0;
int lim;
if(!fs) lim = A[pos]-'0';
else lim = 9;
for(int i = 0; i <= lim; i++) {
if(i == a || i == b) continue;
if(!i && st) ret += solve(pos+1, 10, 10, 1, 1);
else ret += solve(pos+1, b, i, fs | (i < lim), 0);
}
return ret;
}
int main() {
scanf("%lld %lld", &a, &b);
memset(f, -1LL, sizeof f);
sprintf(A, "%lld", b);
ans = solve(0, 10, 10, 0, 1);
if(a) {
memset(f, -1LL, sizeof f);
sprintf(A, "%lld", a-1);
ans -= solve(0, 10, 10, 0, 1);
}
printf("%lld\n", ans);
return 0;
}
Compilation message
numbers.cpp: In function 'int main()':
numbers.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &a, &b);
~~~~~^~~~~~~~~~~~~~~~~~~~~
numbers.cpp:26:5: warning: '__builtin___sprintf_chk' may write a terminating nul past the end of the destination [-Wformat-overflow=]
int main() {
^~~~
In file included from /usr/include/stdio.h:936:0,
from /usr/include/c++/7/cstdio:42,
from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:46,
from numbers.cpp:1:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:34:43: note: '__builtin___sprintf_chk' output between 2 and 21 bytes into a destination of size 20
__bos (__s), __fmt, __va_arg_pack ());
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
716 KB |
Output is correct |
8 |
Correct |
2 ms |
716 KB |
Output is correct |
9 |
Correct |
2 ms |
716 KB |
Output is correct |
10 |
Correct |
2 ms |
716 KB |
Output is correct |
11 |
Correct |
2 ms |
720 KB |
Output is correct |
12 |
Correct |
2 ms |
720 KB |
Output is correct |
13 |
Correct |
2 ms |
720 KB |
Output is correct |
14 |
Correct |
2 ms |
848 KB |
Output is correct |
15 |
Correct |
2 ms |
848 KB |
Output is correct |
16 |
Correct |
2 ms |
848 KB |
Output is correct |
17 |
Correct |
2 ms |
848 KB |
Output is correct |
18 |
Correct |
2 ms |
848 KB |
Output is correct |
19 |
Correct |
2 ms |
848 KB |
Output is correct |
20 |
Correct |
2 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
848 KB |
Output is correct |
2 |
Correct |
3 ms |
848 KB |
Output is correct |
3 |
Correct |
2 ms |
848 KB |
Output is correct |
4 |
Correct |
2 ms |
848 KB |
Output is correct |
5 |
Correct |
2 ms |
848 KB |
Output is correct |
6 |
Correct |
2 ms |
848 KB |
Output is correct |
7 |
Correct |
2 ms |
876 KB |
Output is correct |
8 |
Correct |
2 ms |
876 KB |
Output is correct |
9 |
Correct |
2 ms |
876 KB |
Output is correct |
10 |
Correct |
2 ms |
876 KB |
Output is correct |
11 |
Correct |
2 ms |
876 KB |
Output is correct |
12 |
Correct |
2 ms |
876 KB |
Output is correct |
13 |
Correct |
2 ms |
876 KB |
Output is correct |
14 |
Correct |
2 ms |
876 KB |
Output is correct |
15 |
Correct |
2 ms |
876 KB |
Output is correct |
16 |
Correct |
2 ms |
876 KB |
Output is correct |
17 |
Correct |
2 ms |
876 KB |
Output is correct |
18 |
Correct |
2 ms |
876 KB |
Output is correct |
19 |
Correct |
2 ms |
876 KB |
Output is correct |
20 |
Correct |
2 ms |
876 KB |
Output is correct |
21 |
Correct |
2 ms |
876 KB |
Output is correct |
22 |
Correct |
3 ms |
876 KB |
Output is correct |
23 |
Correct |
2 ms |
876 KB |
Output is correct |
24 |
Correct |
2 ms |
876 KB |
Output is correct |
25 |
Correct |
2 ms |
876 KB |
Output is correct |
26 |
Correct |
2 ms |
876 KB |
Output is correct |
27 |
Correct |
2 ms |
876 KB |
Output is correct |
28 |
Correct |
2 ms |
876 KB |
Output is correct |
29 |
Correct |
2 ms |
876 KB |
Output is correct |
30 |
Correct |
2 ms |
876 KB |
Output is correct |
31 |
Correct |
2 ms |
876 KB |
Output is correct |
32 |
Correct |
2 ms |
876 KB |
Output is correct |
33 |
Correct |
2 ms |
876 KB |
Output is correct |
34 |
Correct |
2 ms |
876 KB |
Output is correct |
35 |
Correct |
2 ms |
876 KB |
Output is correct |
36 |
Correct |
2 ms |
876 KB |
Output is correct |
37 |
Correct |
2 ms |
876 KB |
Output is correct |
38 |
Correct |
2 ms |
876 KB |
Output is correct |
39 |
Correct |
2 ms |
876 KB |
Output is correct |
40 |
Correct |
2 ms |
876 KB |
Output is correct |
41 |
Correct |
2 ms |
876 KB |
Output is correct |
42 |
Correct |
2 ms |
876 KB |
Output is correct |
43 |
Correct |
2 ms |
876 KB |
Output is correct |
44 |
Correct |
2 ms |
876 KB |
Output is correct |
45 |
Correct |
2 ms |
876 KB |
Output is correct |