이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |