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>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
ll dp[20][11][11][2][2];
vector<int> v;
ll rec(int i , int l1 , int l2 , int p , int s){
if(i == (int)v.size()){
return 1;
}
if(dp[i][l1][l2][p][s]!=-1)return dp[i][l1][l2][p][s];
int last = 9;
if(p == 1)last = v[i];
ll res = 0;
for(int j = 0; j <= last; j++){
if(j != l1 && j != l2){
if(j == last){
if(s == 1 && j == 0)
res += rec(i + 1 , 10 , l1 , p , 1);
else res += rec(i + 1 , j , l1 , p , 0);
}
else {
if(s == 1 && j == 0)
res += rec(i + 1 , 10 , l1 , 0 , 1);
else res += rec(i + 1 , j , l1 , 0 , 0);
}
}
}
return dp[i][l1][l2][p][s] = res;
}
void removedigits(ll x){
v.clear();
while(x){
v.pb(x % 10);
x /= 10;
}
reverse(all(v));
}
void solve(){
ll a , b;
cin >> a >> b;
ll ans = 0;
removedigits(b);
memset(dp,-1,sizeof dp);
ans += rec(0 , 10 , 10 , 1 , 1);
removedigits(a-1);
memset(dp,-1,sizeof dp);
ans -= rec(0 , 10 , 10 , 1 , 1);
cout << ans << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t;cin >> t;while(t--)
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |