답안 #855190

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855190 2023-09-30T14:09:37 Z ThylOne Palindrome-Free Numbers (BOI13_numbers) C++14
39.1667 / 100
2 ms 600 KB
#include<bits/stdc++.h>

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