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
ll dp[2][19][11][11], a, b;
ll query(ll x)
{
for (int i=0; i<2; i++) for (int j=0; j<19; j++) for (int k=0; k<=10; k++) for (int l=0; l<=10; l++) dp[i][j][k][l]=0;
int digit=-1, vl, res=0;
while (x>0)
{
vl=x%10;
x/=10;
digit++;
if (digit==0)
{
for (int i=0; i<10; i++) dp[0][digit][10][i]=1;
for (int i=0; i<=vl; i++) dp[1][digit][10][i]=1;
}
if (digit==1)
{
for (int i=0; i<10; i++)
{
for (int j=0; j<10; j++)
{
if (i!=j) dp[0][digit][i][j]+=dp[0][digit-1][10][i];
}
}
for (int i=0; i<10; i++)
{
for (int j=0; j<vl; j++)
{
if (i!=j) dp[1][digit][i][j]+=dp[0][digit-1][10][i];
}
}
for (int i=0; i<10; i++) if (i!=vl) dp[1][digit][i][vl]+=dp[1][digit-1][10][i];
}
if (digit>=2)
{
for (int i=0; i<10; i++)
{
for (int j=0; j<10; j++)
{
for (int k=0; k<10; k++) if (i!=j&&k!=j) dp[0][digit][i][j]+=dp[0][digit-1][k][i];
}
}
for (int i=0; i<10; i++)
{
for (int j=0; j<vl; j++)
{
for (int k=0; k<10; k++) if (i!=j&&k!=j) dp[1][digit][i][j]+=dp[0][digit-1][k][i];
}
}
for (int i=0; i<10; i++) for (int k=0; k<10; k++) if (i!=vl&&vl!=k) dp[1][digit][i][vl]+=dp[1][digit-1][k][i];
}
/*
cout<<"here "<<digit<<'\n';
for (int i=0; i<=10; i++)
{
for (int j=0; j<=10; j++) cout<<dp[0][digit][i][j]<<' ';
cout<<'\n';
}
cout<<"here2 "<<digit<<'\n';
for (int i=0; i<=10; i++)
{
for (int j=0; j<=10; j++) cout<<dp[1][digit][i][j]<<' ';
cout<<'\n';
}*/
if (x!=0) for (int i=0; i<=10; i++) for (int j=1; j<=10; j++) res+=dp[0][digit][i][j];
else for (int i=0; i<=10; i++) for (int j=1; j<=10; j++) res+=dp[1][digit][i][j];
}
return res;
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>a>>b;
cout<<query(b)-query(a-1)<<'\n';
//for (int i=51; i<150; i++) cout<<i<<' '<<query(i)<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |