#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const long long MOD = 1e9+7;
vector<long long> v1;
long long dp[50][32][32][3][3];
long long rec(long long len,long long a,long long b,bool limit, bool leading){
// cout<<" "<<len<<" "<<a<<" "<<b<<" "<<limit<<" "<<leading<<endl;
if(dp[len][a][b][limit][leading]!=-1){
return dp[len][a][b][limit][leading];
}
if(len >= v1.size()-1){
if(len == 2){
//cout<<a<<" "<<b<<endl;
}
return 1;
}
if(limit){
dp[len][a][b][limit][leading] = 0;
for(long long i=0;i<=9;i++){
if(i>v1[len+1]){
break;
}
if(leading && i==0){
if(i==v1[len+1]){
dp[len][a][b][1][leading] += rec(len+1,b,i,1,1);
dp[len][a][b][1][leading]%=MOD;
}else{
dp[len][a][b][1][leading] += rec(len+1,b,i,0,1);
dp[len][a][b][1][leading]%=MOD;
}
continue;
}
if((i!=a && i!=b) && i == v1[len+1]){
dp[len][a][b][1][leading] += rec(len+1,b,i,1,0);
dp[len][a][b][1][leading]%=MOD;
}
else if(i!=a && i!=b){
dp[len][a][b][1][leading] += rec(len+1,b,i,0,0);
dp[len][a][b][1][leading]%=MOD;
}
}
dp[len][a][b][limit][leading]%=MOD;
return dp[len][a][b][limit][leading];
}else{
dp[len][a][b][limit][leading] = 0;
for(long long i=0;i<=9;i++){
if(leading && i==0){
dp[len][a][b][limit][leading] += rec(len+1,b,i,limit,1);
dp[len][a][b][limit][leading]%=MOD;
continue;
}
else if(i!=a && i!=b){
dp[len][a][b][limit][leading] += rec(len+1,b,i,limit,0);
dp[len][a][b][limit][leading]%=MOD;
}
}
dp[len][a][b][limit][leading]%=MOD;
return dp[len][a][b][limit][leading];
}
}
long long solve(long long curr){
v1.clear();
for(long long i=0;i<=49;i++){
for(long long j=0;j<=31;j++){
for(long long k=0;k<=31;k++){
for(long long l=0;l<=2;l++){
for(long long m=0;m<=2;m++){
dp[i][j][k][l][m] = -1;
}
}
}
}
}
while(curr){
v1.push_back(curr%10);
curr/=10;
}
v1.push_back(0);
reverse(v1.begin(),v1.end());
long long ans = 0;
for(long long i=0;i<=9;i++){
if(v1[1]<i){
break;
}
if(v1[i] ==0){
ans+=rec(1,30,0,false,true);
ans%=MOD;
continue;
}
ans+=rec(1,30,i,v1[1] == i,false);
ans%=MOD;
}
return ans;
}
int main(){
long long a,b;
cin>>a>>b;
cout<<solve(b)-solve(a-1)<<endl;
}
Compilation message
numbers.cpp: In function 'long long int rec(long long int, long long int, long long int, bool, bool)':
numbers.cpp:14:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(len >= v1.size()-1){
~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
2 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
3 |
Correct |
5 ms |
3960 KB |
Output is correct |
4 |
Incorrect |
5 ms |
3832 KB |
Output isn't correct |
5 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
6 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
7 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
8 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
9 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
10 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
11 |
Correct |
5 ms |
3960 KB |
Output is correct |
12 |
Correct |
5 ms |
3960 KB |
Output is correct |
13 |
Correct |
5 ms |
3936 KB |
Output is correct |
14 |
Incorrect |
5 ms |
3928 KB |
Output isn't correct |
15 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
16 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
17 |
Incorrect |
6 ms |
3960 KB |
Output isn't correct |
18 |
Correct |
5 ms |
3960 KB |
Output is correct |
19 |
Correct |
5 ms |
3952 KB |
Output is correct |
20 |
Incorrect |
6 ms |
4012 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3960 KB |
Output is correct |
2 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
3 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
4 |
Incorrect |
6 ms |
3960 KB |
Output isn't correct |
5 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
6 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
7 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
8 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
9 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
10 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
11 |
Correct |
5 ms |
3960 KB |
Output is correct |
12 |
Incorrect |
5 ms |
3932 KB |
Output isn't correct |
13 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
14 |
Incorrect |
5 ms |
3964 KB |
Output isn't correct |
15 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
16 |
Correct |
6 ms |
3960 KB |
Output is correct |
17 |
Correct |
7 ms |
3960 KB |
Output is correct |
18 |
Correct |
6 ms |
3960 KB |
Output is correct |
19 |
Correct |
6 ms |
3960 KB |
Output is correct |
20 |
Incorrect |
6 ms |
3940 KB |
Output isn't correct |
21 |
Incorrect |
6 ms |
3948 KB |
Output isn't correct |
22 |
Correct |
6 ms |
3960 KB |
Output is correct |
23 |
Incorrect |
6 ms |
3960 KB |
Output isn't correct |
24 |
Correct |
6 ms |
3960 KB |
Output is correct |
25 |
Incorrect |
6 ms |
3960 KB |
Output isn't correct |
26 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
27 |
Incorrect |
6 ms |
3960 KB |
Output isn't correct |
28 |
Incorrect |
6 ms |
3960 KB |
Output isn't correct |
29 |
Correct |
6 ms |
4088 KB |
Output is correct |
30 |
Correct |
6 ms |
3960 KB |
Output is correct |
31 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
32 |
Correct |
6 ms |
3960 KB |
Output is correct |
33 |
Incorrect |
6 ms |
3960 KB |
Output isn't correct |
34 |
Correct |
6 ms |
3960 KB |
Output is correct |
35 |
Incorrect |
6 ms |
3964 KB |
Output isn't correct |
36 |
Incorrect |
5 ms |
3960 KB |
Output isn't correct |
37 |
Incorrect |
5 ms |
3964 KB |
Output isn't correct |
38 |
Incorrect |
6 ms |
3960 KB |
Output isn't correct |
39 |
Incorrect |
6 ms |
3964 KB |
Output isn't correct |
40 |
Correct |
7 ms |
3960 KB |
Output is correct |
41 |
Incorrect |
6 ms |
3964 KB |
Output isn't correct |
42 |
Correct |
6 ms |
3932 KB |
Output is correct |
43 |
Incorrect |
6 ms |
3952 KB |
Output isn't correct |
44 |
Incorrect |
6 ms |
3960 KB |
Output isn't correct |
45 |
Incorrect |
5 ms |
3936 KB |
Output isn't correct |