Submission #779888

# Submission time Handle Problem Language Result Execution time Memory
779888 2023-07-12T02:06:54 Z vjudge1 Palindrome-Free Numbers (BOI13_numbers) C++17
100 / 100
1 ms 340 KB
#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;
}

Compilation message

numbers.cpp: In function 'll solve(int, int, int, int, int)':
numbers.cpp:8:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  if(id==digit.size()&&check==1) return 1;
      |     ~~^~~~~~~~~~~~~~
numbers.cpp:9:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |  if(id==digit.size()&&check==0) return 0;
      |     ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct