#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 5e8 + 1;
int dp[20][10][10][2];
int x,y, tmp,cnt;
vector<int>v;
int calc(int i, int sec, int lst, int con){
if(i >= (int)v.size())return 1;
if(dp[i][sec][lst][con]>0)return dp[i][sec][lst][con];
if(con){
int ans =0;
if(i && lst && sec && v[i])ans += calc(i+1, lst,0 ,0);
for(int j=1;j<v[i];j++)if(j != lst && j != sec)ans += calc(i+1, lst, j, 0);
if(v[i] != lst && v[i] != sec)ans += calc(i+1, lst, v[i], 1);
//cout << i << " " << sec << " " << lst << " " << con << " " << ans << '\n';
return dp[i][sec][lst][con]= ans;
}
else{
int ans =0;
if(i && sec && lst)ans += calc(i+1, lst, 0, 0);
for(int j=1;j<=9;j++)if(j != lst && j != sec)ans += calc(i+1, lst, j, 0);
return dp[i][sec][lst][con] = ans;
}
}
main(){
//ios::sync_with_stdio(0);cin.tie(0);
cin >> x >> y;
if(y == 0)return cout << 1, 0;
tmp = y;
cnt =0;
int tmp2 = y;
while(tmp2)v.push_back(tmp2%10), tmp2 /= 10;
reverse(v.begin(), v.end());
memset(dp, -1, sizeof(dp));
int ans1 = calc(0, 10, 10, 1);
//cout << ans1 << '\n';
v.pop_back();
while(v.size()){
memset(dp, -1, sizeof(dp));
ans1 += calc(0, 10, 10, 0);
//cout << ans1 << '\n';
v.pop_back();
}
//cout << ans1 << '\n';
if(x == 0)return cout << ans1+1, 0;
else if(x == 1)return cout << ans1, 0;
tmp = --x;
v.clear();
memset(dp,-1, sizeof(dp));
while(tmp > 0)v.push_back(tmp%10), tmp/=10;
reverse(v.begin(), v.end());
int ans2 = calc(0, 10, 10, 1);
v.pop_back();
while(v.size()){
memset(dp, -1, sizeof(dp));
ans2 += calc(0, 10, 10, 0);
v.pop_back();
}
cout << ans1 - ans2 << '\n';
}
Compilation message
numbers.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
26 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
304 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
304 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
304 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 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 |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
2 ms |
308 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 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 |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
304 KB |
Output is correct |
20 |
Correct |
2 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
212 KB |
Output is correct |
22 |
Correct |
2 ms |
300 KB |
Output is correct |
23 |
Correct |
2 ms |
304 KB |
Output is correct |
24 |
Correct |
3 ms |
336 KB |
Output is correct |
25 |
Correct |
2 ms |
212 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
212 KB |
Output is correct |
28 |
Correct |
2 ms |
212 KB |
Output is correct |
29 |
Correct |
2 ms |
304 KB |
Output is correct |
30 |
Correct |
2 ms |
212 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
212 KB |
Output is correct |
33 |
Correct |
2 ms |
212 KB |
Output is correct |
34 |
Correct |
2 ms |
304 KB |
Output is correct |
35 |
Correct |
2 ms |
212 KB |
Output is correct |
36 |
Correct |
2 ms |
212 KB |
Output is correct |
37 |
Correct |
2 ms |
340 KB |
Output is correct |
38 |
Correct |
2 ms |
212 KB |
Output is correct |
39 |
Correct |
2 ms |
212 KB |
Output is correct |
40 |
Correct |
2 ms |
212 KB |
Output is correct |
41 |
Correct |
2 ms |
212 KB |
Output is correct |
42 |
Correct |
2 ms |
300 KB |
Output is correct |
43 |
Correct |
2 ms |
212 KB |
Output is correct |
44 |
Correct |
2 ms |
300 KB |
Output is correct |
45 |
Correct |
2 ms |
212 KB |
Output is correct |