| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 248563 | 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][10][10][2];
ll dp(int ind, int secondlast, int last, bool isSame){
if (ind==s.size()){
return 1;
}
if (secondlast!=-1&&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 || i==secondlast){continue;}
total+=dp(ind+1,last,i,isSame&&i==(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<10; j++){
for (int k = 0; k<10; 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,-1,-1,true);
if (a>=0){
s=to_string(a);
initdp();
tot-=dp(0,-1,-1,true);
}
cout<<tot<<'\n';
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
