# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
779888 | vjudge1 | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 1 ms | 340 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
bool csgt=false;
if(last1==18&&last2==18){
if(i==0){
csgt=true;
}
}
if(i==prelast1){
precheck=false;
}
if(i==prelast2){
precheck=false;
}
//cout<<prelast1<<" "<<prelast2<<" "<<i<<"#";
if(precheck==true){
prelast1=i;
prelast2=last1;
if(csgt==true){
prelast1=18;
prelast2=18;
}
//cout<<prelast1<<" "<<prelast2<<" "<<i<<"#";
res+=solve(id+1,preflag,prelast1,prelast2,precheck);
}
}
return dp[id][flag][last1][last2]=res;
}
ll get(ll a){
if(a==-1) return 0;
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(0);
//cout<<get(b)<<" "<<get(a-1);
ll kqua=get(b)-get(a-1);
cout<<kqua;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |