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 int long long
using namespace std;
int n;
int a[20];
int dp[20][2][11][11];
int cnt(int pos,int k,int fi,int se)
{
// cout<<pos<<' '<<k<<" "<<fi<<" "<<se<<'\n';
if(pos==n) return 1;
if(dp[pos][k][fi][se]!=-1) return dp[pos][k][fi][se];
int upper=a[pos];
if(k) upper=9;
int ans=0;
for(int i=0;i<=upper;i++)
{
if(i==fi or i==se) continue;
if(i==0 and fi==10 and se==10)
{
ans+=cnt(pos+1,1,fi,se);
}
else
{
ans+=cnt(pos+1,(k or i<a[pos]),se,i);
}
}
return dp[pos][k][fi][se]=ans;
}
int solve(int x)
{
memset(dp,-1,sizeof(dp));
n=0;
while(x)
{
a[n++]=x%10;
x/=10;
}
reverse(a,a+n);
return cnt(0,0,10,10);
}
signed main()
{
int l,r;
cin>>l>>r;
cout<<solve(r)-solve(l-1);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |