#include <bits/stdc++.h>
using namespace std;
long long a,b;
bool used[22][2][10][10][2][2];
long long state[22][2][10][10][2][2];
int d[22],cnt;
int get_digits(long long n) {
cnt=0;
while(n) d[cnt++]=n%10,n/=10;
reverse(d,d+cnt);
}
long long recurse(int pos, int f, int before_last, int last, int has_before_last, int has_last) {
if(pos==cnt) return has_last;
if(used[pos][f][before_last][last][has_before_last][has_last]) return state[pos][f][before_last][last][has_before_last][has_last];
long long ans=0;
int i;
for(i=0;i<10;i++) {
if(f || i<=d[pos]) if(!has_last || last!=i) if(!has_before_last || before_last!=i) {
ans+=recurse(pos+1,f|(i<d[pos]),last,i,has_last,has_last|(i>0));
}
}
used[pos][f][before_last][last][has_before_last][has_last]=true;
state[pos][f][before_last][last][has_before_last][has_last]=ans;
return ans;
}
long long f(long long n) {
if(n<10) return n;
get_digits(n);
memset(used,0,sizeof(used));
return recurse(0,0,0,0,0,0);
}
int main() {
scanf("%lld %lld", &a, &b);
printf("%lld\n", f(b)-((a==0) ? 0 : f(a-1)));
}
Compilation message
numbers.cpp: In function 'int get_digits(long long int)':
numbers.cpp:14:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
numbers.cpp: In function 'int main()':
numbers.cpp:39:31: 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 |
0 ms |
2172 KB |
Output is correct |
2 |
Correct |
0 ms |
2172 KB |
Output is correct |
3 |
Correct |
0 ms |
2172 KB |
Output is correct |
4 |
Incorrect |
0 ms |
2172 KB |
Output isn't correct |
5 |
Correct |
0 ms |
2172 KB |
Output is correct |
6 |
Correct |
0 ms |
2172 KB |
Output is correct |
7 |
Correct |
0 ms |
2172 KB |
Output is correct |
8 |
Correct |
0 ms |
2172 KB |
Output is correct |
9 |
Correct |
0 ms |
2172 KB |
Output is correct |
10 |
Correct |
0 ms |
2172 KB |
Output is correct |
11 |
Correct |
0 ms |
2172 KB |
Output is correct |
12 |
Correct |
0 ms |
2172 KB |
Output is correct |
13 |
Correct |
0 ms |
2172 KB |
Output is correct |
14 |
Incorrect |
0 ms |
2172 KB |
Output isn't correct |
15 |
Correct |
0 ms |
2172 KB |
Output is correct |
16 |
Correct |
0 ms |
2172 KB |
Output is correct |
17 |
Correct |
0 ms |
2172 KB |
Output is correct |
18 |
Incorrect |
0 ms |
2172 KB |
Output isn't correct |
19 |
Correct |
0 ms |
2172 KB |
Output is correct |
20 |
Correct |
0 ms |
2172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2172 KB |
Output is correct |
2 |
Correct |
0 ms |
2172 KB |
Output is correct |
3 |
Correct |
0 ms |
2172 KB |
Output is correct |
4 |
Correct |
0 ms |
2172 KB |
Output is correct |
5 |
Correct |
0 ms |
2172 KB |
Output is correct |
6 |
Correct |
0 ms |
2172 KB |
Output is correct |
7 |
Correct |
0 ms |
2172 KB |
Output is correct |
8 |
Correct |
0 ms |
2172 KB |
Output is correct |
9 |
Correct |
0 ms |
2172 KB |
Output is correct |
10 |
Correct |
0 ms |
2172 KB |
Output is correct |
11 |
Correct |
0 ms |
2172 KB |
Output is correct |
12 |
Correct |
0 ms |
2172 KB |
Output is correct |
13 |
Correct |
0 ms |
2172 KB |
Output is correct |
14 |
Correct |
0 ms |
2172 KB |
Output is correct |
15 |
Correct |
0 ms |
2172 KB |
Output is correct |
16 |
Correct |
0 ms |
2172 KB |
Output is correct |
17 |
Correct |
0 ms |
2172 KB |
Output is correct |
18 |
Correct |
0 ms |
2172 KB |
Output is correct |
19 |
Correct |
0 ms |
2172 KB |
Output is correct |
20 |
Correct |
0 ms |
2172 KB |
Output is correct |
21 |
Correct |
0 ms |
2172 KB |
Output is correct |
22 |
Correct |
0 ms |
2172 KB |
Output is correct |
23 |
Correct |
0 ms |
2172 KB |
Output is correct |
24 |
Correct |
0 ms |
2172 KB |
Output is correct |
25 |
Correct |
0 ms |
2172 KB |
Output is correct |
26 |
Correct |
0 ms |
2172 KB |
Output is correct |
27 |
Correct |
0 ms |
2172 KB |
Output is correct |
28 |
Correct |
0 ms |
2172 KB |
Output is correct |
29 |
Correct |
0 ms |
2172 KB |
Output is correct |
30 |
Correct |
0 ms |
2172 KB |
Output is correct |
31 |
Correct |
0 ms |
2172 KB |
Output is correct |
32 |
Correct |
0 ms |
2172 KB |
Output is correct |
33 |
Correct |
0 ms |
2172 KB |
Output is correct |
34 |
Correct |
0 ms |
2172 KB |
Output is correct |
35 |
Correct |
0 ms |
2172 KB |
Output is correct |
36 |
Correct |
0 ms |
2172 KB |
Output is correct |
37 |
Correct |
0 ms |
2172 KB |
Output is correct |
38 |
Correct |
0 ms |
2172 KB |
Output is correct |
39 |
Correct |
0 ms |
2172 KB |
Output is correct |
40 |
Correct |
0 ms |
2172 KB |
Output is correct |
41 |
Correct |
0 ms |
2172 KB |
Output is correct |
42 |
Correct |
0 ms |
2172 KB |
Output is correct |
43 |
Correct |
0 ms |
2172 KB |
Output is correct |
44 |
Correct |
0 ms |
2172 KB |
Output is correct |
45 |
Correct |
0 ms |
2172 KB |
Output is correct |