#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int dpv[20][10][10][2];
ll dp(int ind, int secondlast, int last, bool isSame){
if (ind==s.size()){
return 1;
}
if (secondlast!=-1&&dpv[ind][secondlast][last][isSame]!=-1){
return dpv[ind][secondlast][last][isSame];
}
int upper = isSame ? s[ind]-'0' : 9;
ll total = 0;
for (int i = 0; i<=upper; i++){
if (i==last || i==secondlast){continue;}
total+=dp(ind+1,last,i,isSame&&i==(s[ind]-'0'));
}
if (secondlast!=-1){
dpv[ind][secondlast][last][isSame]=total;
}
return total;
}
void initdp(){
for (int i = 0; i<20; i++){
for (int j = 0; j<10; j++){
for (int k = 0; k<10; k++){
for (int l = 0; l<2; l++){
dpv[i][j][k][l]=-1;
}
}
}
}
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
ll a,b;
cin>>a>>b;
a--;
s=to_string(b);
initdp();
ll tot = dp(0,-1,-1,true);
if (a>=0){
s=to_string(a);
initdp();
tot-=dp(0,-1,-1,true);
}
cout<<tot<<'\n';
}
Compilation message
numbers.cpp: In function 'll dp(int, int, int, bool)':
numbers.cpp:10:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (ind==s.size()){
~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
7 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
8 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
9 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
13 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
36 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
37 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
38 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
39 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
40 |
Correct |
1 ms |
384 KB |
Output is correct |
41 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
44 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
45 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |