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], dp[30][30][30][2], l, r, i, j, k, t, n, ans;
ll A(ll x){
memset(dp, 0, sizeof(dp)); ans=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++)
dp[2][j][k][0]=(j!=k)*(j<a[1]||k<a[2]),
dp[2][j][k][1]=(j!=k)*(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++)
dp[i+1][k][t][0]+=(dp[i][j][k][0]+dp[i][j][k][1]*(t<a[i+1])*(k==a[i]))*(t!=k)*(t!=j)*(k!=j),
dp[i+1][k][t][1]+=dp[i][j][k][1]*(k==a[i])*(t==a[i+1])*(t!=k)*(t!=j)*(k!=j);
for (j=0; j<=9; j++)
for (k=0; k<=9; k++)
ans+=dp[n][j][k][0]+dp[n][j][k][1];
for(i=0;i<n-2;i++)ans+=81<<(3*i);
if(n<2)return x+1; return ans+10;
}
int main(){cin>>l>>r; if(l<100)cout<<1/0; cout<<A(r)-A(l-1);}
Compilation message (stderr)
numbers.cpp: In function 'long long int A(long long int)':
numbers.cpp:16:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (j=0; j<=9; j++)
^~~
numbers.cpp:20:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for(i=0;i<n-2;i++)ans+=81<<(3*i);
^~~
numbers.cpp:21:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(n<2)return x+1; return ans+10;
^~
numbers.cpp:21: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 ans+10;
^~~~~~
numbers.cpp: In function 'int main()':
numbers.cpp:23:39: warning: division by zero [-Wdiv-by-zero]
int main(){cin>>l>>r; if(l<100)cout<<1/0; cout<<A(r)-A(l-1);}
~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |