#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define ll long long
#define int ll
using namespace std;
string str;
int dp[20][20][55][5][5];
int get(int last2 = 10,int last = 10,int pos = 0,int sm = 0,int p = 0){
if (pos >= str.size()) return dp[last2][last][pos][sm][p] = 1;
if (dp[last2][last][pos][sm][p] != -1)
return dp[last2][last][pos][sm][p];
int l = 9,sum=0;
if (!sm) l = str[pos] - '0';
for (int i=0;i<=l;i++){
if (i == last || i == last2) continue;
int sm2 = sm;
if (!sm2 && i < l) sm2 = 1;
if (!i && !p) sum += get(10,10,pos+1,sm2,0);
else sum += get(last,i,pos + 1,sm2,1);
}
return dp[last2][last][pos][sm][p] = sum;
}
int G(int x){
if (x <= 0) return 0;
memset(dp, -1, sizeof(dp));
str = "";
while(x){
str+=(x%10)+'0';
x/=10;
}
reverse(str.begin(),str.end());
return get();
}
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
ll a,b;
cin>>a>>b;
cout<<G(b) - G(a - 1)<<"\n";
}
Compilation message
numbers.cpp: In function 'long long int get(long long int, long long int, long long int, long long int, long long int)':
numbers.cpp:13:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | if (pos >= str.size()) return dp[last2][last][pos][sm][p] = 1;
| ~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4556 KB |
Output is correct |
2 |
Correct |
2 ms |
4556 KB |
Output is correct |
3 |
Correct |
3 ms |
4556 KB |
Output is correct |
4 |
Correct |
2 ms |
4556 KB |
Output is correct |
5 |
Incorrect |
3 ms |
4556 KB |
Output isn't correct |
6 |
Incorrect |
3 ms |
4556 KB |
Output isn't correct |
7 |
Correct |
3 ms |
4556 KB |
Output is correct |
8 |
Correct |
3 ms |
4556 KB |
Output is correct |
9 |
Correct |
2 ms |
4556 KB |
Output is correct |
10 |
Correct |
4 ms |
4556 KB |
Output is correct |
11 |
Correct |
3 ms |
4556 KB |
Output is correct |
12 |
Correct |
3 ms |
4556 KB |
Output is correct |
13 |
Correct |
3 ms |
4556 KB |
Output is correct |
14 |
Correct |
3 ms |
4556 KB |
Output is correct |
15 |
Incorrect |
2 ms |
4556 KB |
Output isn't correct |
16 |
Correct |
2 ms |
4556 KB |
Output is correct |
17 |
Correct |
2 ms |
4556 KB |
Output is correct |
18 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
19 |
Correct |
3 ms |
4556 KB |
Output is correct |
20 |
Correct |
2 ms |
4556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4556 KB |
Output is correct |
2 |
Correct |
3 ms |
4556 KB |
Output is correct |
3 |
Correct |
4 ms |
4536 KB |
Output is correct |
4 |
Correct |
2 ms |
4556 KB |
Output is correct |
5 |
Correct |
3 ms |
4556 KB |
Output is correct |
6 |
Correct |
2 ms |
4556 KB |
Output is correct |
7 |
Correct |
2 ms |
4556 KB |
Output is correct |
8 |
Correct |
2 ms |
4556 KB |
Output is correct |
9 |
Correct |
2 ms |
4556 KB |
Output is correct |
10 |
Correct |
2 ms |
4556 KB |
Output is correct |
11 |
Correct |
2 ms |
4556 KB |
Output is correct |
12 |
Correct |
2 ms |
4556 KB |
Output is correct |
13 |
Correct |
2 ms |
4556 KB |
Output is correct |
14 |
Correct |
2 ms |
4556 KB |
Output is correct |
15 |
Correct |
2 ms |
4556 KB |
Output is correct |
16 |
Correct |
3 ms |
4556 KB |
Output is correct |
17 |
Correct |
2 ms |
4556 KB |
Output is correct |
18 |
Correct |
2 ms |
4556 KB |
Output is correct |
19 |
Correct |
2 ms |
4556 KB |
Output is correct |
20 |
Correct |
2 ms |
4556 KB |
Output is correct |
21 |
Correct |
2 ms |
4556 KB |
Output is correct |
22 |
Correct |
3 ms |
4556 KB |
Output is correct |
23 |
Correct |
3 ms |
4556 KB |
Output is correct |
24 |
Correct |
3 ms |
4556 KB |
Output is correct |
25 |
Correct |
3 ms |
4556 KB |
Output is correct |
26 |
Correct |
3 ms |
4556 KB |
Output is correct |
27 |
Correct |
2 ms |
4556 KB |
Output is correct |
28 |
Correct |
2 ms |
4556 KB |
Output is correct |
29 |
Correct |
2 ms |
4556 KB |
Output is correct |
30 |
Correct |
3 ms |
4556 KB |
Output is correct |
31 |
Correct |
2 ms |
4556 KB |
Output is correct |
32 |
Correct |
2 ms |
4556 KB |
Output is correct |
33 |
Correct |
2 ms |
4556 KB |
Output is correct |
34 |
Correct |
2 ms |
4556 KB |
Output is correct |
35 |
Correct |
2 ms |
4616 KB |
Output is correct |
36 |
Correct |
2 ms |
4556 KB |
Output is correct |
37 |
Correct |
2 ms |
4556 KB |
Output is correct |
38 |
Correct |
2 ms |
4556 KB |
Output is correct |
39 |
Correct |
3 ms |
4556 KB |
Output is correct |
40 |
Correct |
2 ms |
4556 KB |
Output is correct |
41 |
Correct |
3 ms |
4556 KB |
Output is correct |
42 |
Correct |
3 ms |
4556 KB |
Output is correct |
43 |
Correct |
2 ms |
4556 KB |
Output is correct |
44 |
Correct |
3 ms |
4556 KB |
Output is correct |
45 |
Correct |
3 ms |
4556 KB |
Output is correct |