# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
248568 | eohomegrownapps | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 1 ms | 384 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 s;
ll dpv[20][11][11][2];
ll dp(int ind, int secondlast, int last, bool isSame){
if (ind==s.size()){
return 1;
}
if (dpv[ind][secondlast][last][isSame]!=-1){
return dpv[ind][secondlast][last][isSame];
}
int upper = isSame ? s[ind]-'0' : 9;
ll total = 0;
for (int i = 0; i<=upper; i++){
if ((i==last&&last!=10) || (i==secondlast&&secondlast!=10)){continue;}
int ival = i;
if (i==0&&last==10){
ival = 10;
}
total+=dp(ind+1,last,ival,isSame&&ival==(s[ind]-'0'));
}
if (secondlast!=-1){
dpv[ind][secondlast][last][isSame]=total;
}
return total;
}
void initdp(){
for (int i = 0; i<20; i++){
for (int j = 0; j<11; j++){
for (int k = 0; k<11; k++){
for (int l = 0; l<2; l++){
dpv[i][j][k][l]=-1;
}
}
}
}
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
ll a,b;
cin>>a>>b;
a--;
s=to_string(b);
initdp();
ll tot = dp(0,10,10,true);
if (a>=0){
s=to_string(a);
initdp();
tot-=dp(0,10,10,true);
}
cout<<tot<<'\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |