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 check(string a){
for (int i = 1; i < a.size(); i++){
if (a[i] == a[i - 1]) return 0;
if (i > 1 && a[i] == a[i - 2]) return 0;
}
return 1;
}
int G(string a){
str = a;
memset(dp, -1, sizeof(dp));
return get();
}
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
string a,b;
cin>>a>>b;
cout<<G(b) - G(a) + check(a)<<"\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;
| ~~~~^~~~~~~~~~~~~
numbers.cpp: In function 'long long int check(std::string)':
numbers.cpp:32:23: 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]
32 | for (int i = 1; i < a.size(); i++){
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |