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
#define f(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
ll a[30],d[30][30][30][2],l,r,n,U;
ll A(ll x){
memset(d,0,sizeof(d));U=0;
string s=to_string(x);n=s.size();
f(i,1,n)a[i]=s[i-1]-'0';
f(j,1,a[1])f(k,0,9)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]);
f(i,2,n)f(j,0,9)f(k,0,9){U+=(d[i][j][k][0]+d[i][j][k][1])*(n==i);f(t,0,9)
if(k-j&&k-t&&t-j)d[i+1][k][t][1]+=d[i][j][k][1]*(k==a[i])*(t==a[i+1]),
d[i+1][k][t][0]+=d[i][j][k][0]+d[i][j][k][1]*(t<a[i+1])*(k==a[i]);}
f(i,0,n-3)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:17:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(n<2)return x+1; return U+10;
^~
numbers.cpp:17: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:19: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... |