Submission #779866

# Submission time Handle Problem Language Result Execution time Memory
779866 2023-07-12T01:43:33 Z vjudge1 Palindrome-Free Numbers (BOI13_numbers) C++17
71.25 / 100
1 ms 412 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;
		}
		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

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 Incorrect 1 ms 324 KB Output isn't correct
2 Incorrect 1 ms 328 KB Output isn't correct
3 Correct 1 ms 324 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Incorrect 1 ms 328 KB Output isn't correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Incorrect 0 ms 340 KB Output isn't correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Incorrect 1 ms 340 KB Output isn't correct
19 Correct 1 ms 340 KB Output is correct
20 Incorrect 1 ms 320 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Correct 1 ms 320 KB Output is correct
7 Incorrect 1 ms 324 KB Output isn't correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Correct 1 ms 328 KB Output is correct
12 Incorrect 1 ms 340 KB Output isn't correct
13 Incorrect 1 ms 324 KB Output isn't correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Incorrect 1 ms 320 KB Output isn't correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 412 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 324 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 320 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 324 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 324 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 320 KB Output is correct
45 Correct 1 ms 340 KB Output is correct