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 ll long long
using namespace std;
ll a[30],d[30][30][30][2],l,r,i,j,k,t,n,U;
ll A(ll x){
memset(d,0,sizeof(d));U=0;
string s=to_string(x);n=s.size();
for(i=1;i<=n;i++)a[i]=s[i-1]-'0';
for(j=1;j<=a[1];j++)for(k=0;k<=9;k++)if(k-j)
d[2][j][k][0]=(j<a[1]||k<a[2]),
d[2][j][k][1]=(j==a[1])*(k==a[2]);
for(i=2;i<n;i++)for(j=0;j<=9;j++)for(k=0;k<=9;k++)for(t=0;t<=9;t++)if(k-j&&k-t&&t-j)
d[i+1][k][t][0]+=d[i][j][k][0]+d[i][j][k][1]*(t<a[i+1])*(k==a[i]),
d[i+1][k][t][1]+=d[i][j][k][1]*(k==a[i])*(t==a[i+1]);
for(j=0;j<=9;j++)for(k=0;k<=9;k++)U+=d[n][j][k][0]+d[n][j][k][1];
for(i=0;i<n-2;i++)U+=81<<(3*i);
if(n<2)return x+1; return U+10;
}
main(){cin>>l>>r; cout<<A(r)-min(2*l,A(l-1));}
Compilation message (stderr)
numbers.cpp: In function 'long long int A(long long int)':
numbers.cpp:18:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(n<2)return x+1; return U+10;
^~
numbers.cpp:18:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(n<2)return x+1; return U+10;
^~~~~~
numbers.cpp: At global scope:
numbers.cpp:20:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){cin>>l>>r; cout<<A(r)-min(2*l,A(l-1));}
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |