This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 = 1){
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,p2 = p;
if (!sm2 && i < l) sm2 = 1;
if (i && p2) p2 = 0;
if (p2) sm2 = 1;
if (p2) sum += get(10,10,pos+1,sm2,p2);
else sum += get(last,i,pos + 1,sm2,p2);
}
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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |