# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
779866 | vjudge1 | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 1 ms | 412 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;
using ll=long long;
vector<int> digit;
ll dp[20][2][19][19];
ll solve(int id,int flag,int last1,int last2,int check){
//cout<<last1<<" "<<last2<<"#"<<endl;
if(id==digit.size()&&check==1) return 1;
if(id==digit.size()&&check==0) return 0;
if(dp[id][flag][last1][last2]!=-1) return dp[id][flag][last1][last2];
int pos;
if(flag==1){
pos=9;
}
if(flag==0){
pos=digit[id];
}
ll res=0;
for(int i=0;i<=pos;++i){
int preflag=flag;
int prelast1=last1;
int prelast2=last2;
int precheck=check;
if(i!=pos){
preflag=1;
}
if(i==prelast1){
precheck=false;
}
if(i==prelast2){
precheck=false;
}
//cout<<prelast1<<" "<<prelast2<<" "<<i<<"#";
if(precheck==true){
prelast1=i;
prelast2=last1;
//cout<<prelast1<<" "<<prelast2<<" "<<i<<"#";
res+=solve(id+1,preflag,prelast1,prelast2,precheck);
}
}
return dp[id][flag][last1][last2]=res;
}
ll get(ll a){
digit.clear();
while(a>0){
digit.push_back(a%10);
a/=10;
}
reverse(digit.begin(),digit.end());
// for(auto item:digit) cout<<item<<" ";
memset(dp,-1,sizeof(dp));
ll kqua=solve(0,0,18,18,1);
return kqua;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll a;
ll b;
cin>>a>>b;
//cout<<get(a);
//cout<<get(b)<<" "<<get(a);
ll kqua=get(b)-get(a-1);
cout<<kqua;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |