Submission #855191

# Submission time Handle Problem Language Result Execution time Memory
855191 2023-09-30T14:12:08 Z ThylOne Palindrome-Free Numbers (BOI13_numbers) C++14
72.5 / 100
1 ms 600 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
string limit;
int dpTab[2][20][12][12];
int dp(bool L,int pos=0,int last1=10,int last2=10){
	if(pos==limit.size())return 1;
	if(dpTab[L][pos][last1][last2]!=-1)
		return dpTab[L][pos][last1][last2];
	
	int cnt=0;
	int borne = (limit[pos]-'0');
	if(!L)borne=9;
	for(int digit=0;digit<=borne;digit++){
		if(digit!=last1 && digit!=last2){
			int L2 = (borne==digit);
			if(L==false)L2=false;
			cnt+=dp(L2,pos+1,digit,last1);
		}
	}
	dpTab[L][pos][last1][last2] = cnt;
	return dpTab[L][pos][last1][last2];
	
}

void setDp(ll lim){
	limit = to_string(lim);
	for(int b=0;b<2;b++){
		for(int pos=0;pos<20;pos++){
			for(int last1=0;last1<=10;last1++){
				for(int last2=0;last2<=10;last2++){
					dpTab[b][pos][last1][last2]=-1;
				}
			}
		}
	}
}
signed main(){
	ll a,b;
	cin>>a>>b;
	int cnt=0;
	setDp(b);
	cnt+=dp(true,0,10,10);
	setDp(a-1);
	cnt-=dp(true,0,10,10);
	cout<<cnt<<endl;
	return 0;
}

Compilation message

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