# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
855190 | ThylOne | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 2 ms | 600 KiB |
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;
typedef long long ll;
string limit;
int dpTab[2][20][12][12];
int dp(bool L,int pos=0,int last1=10,int last2=10){
if(pos==limit.size())return 1;
if(dpTab[L][pos][last1][last2]!=-1)
return dpTab[L][pos][last1][last2];
int cnt=0;
int borne = (limit[pos]-'0');
if(!L)borne=9;
for(int digit=0;digit<=borne;digit++){
if(digit!=last1 && digit!=last2){
int L2 = (borne==digit);
if(L==false)L2=false;
cnt+=dp(L2,pos+1,digit,last1);
}
}
dpTab[L][pos][last1][last2] = cnt;
return dpTab[L][pos][last1][last2];
}
void setDp(ll lim){
limit = to_string(lim);
for(int b=0;b<2;b++){
for(int pos=0;pos<20;pos++){
for(int last1=0;last1<=10;last1++){
for(int last2=0;last2<=10;last2++){
dpTab[b][pos][last1][last2]=-1;
}
}
}
}
}
signed main(){
ll a,b;
cin>>a>>b;
int cnt=0;
setDp(b);
cnt+=dp(true,0,10,10);
setDp(a-1);
cnt-=dp(true,0,10,10);
cout<<cnt<<endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |