답안 #74679

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74679 2018-09-06T11:28:51 Z kjain_1810 Palindrome-Free Numbers (BOI13_numbers) C++17
100 / 100
3 ms 724 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
const int MAXL = 25;
const int MAXD = 12;
 
ll dp[MAXL][MAXD][MAXD][2][2];
vector<int> digitos;
int N;
ll A,B;
 
ll solve(int pos,int l1,int l2,int flag,int leading){
	ll &ret = dp[pos][l1][l2][flag][leading];
	if(ret != -1) return ret;
	ret = 0;
	if(pos == N){
		ret = 1;
		return ret;
	}
	int limite = 9;
	if(flag) limite = digitos[pos];
	for(int i = 0;i<=limite;i++){
		if(leading == 1 && i == 0){
			ret += solve(pos+1,l1,l2,flag && (i == limite),leading);
		}
		else{
			if(l1 != i && l2 != i) ret += solve(pos+1,i,l1,flag && (i == limite), 0);
		}
	}
	return ret;
}
 
ll calcula(ll X){
	if(X == -1) return 0;
	if(X == 0) return 1;
	digitos.clear();
	memset(dp,-1,sizeof(dp));
	while(X != 0){
		digitos.push_back(X % 10);
		X /= 10;
	}
	reverse(digitos.begin(),digitos.end());
	N = digitos.size();
	return solve(0,10,10,1,1);
}
 
int main(){
 
	cin >> A >> B;
	cout << calcula(B) - calcula(A-1) << endl;
 
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 500 KB Output is correct
6 Correct 2 ms 664 KB Output is correct
7 Correct 2 ms 664 KB Output is correct
8 Correct 2 ms 664 KB Output is correct
9 Correct 2 ms 664 KB Output is correct
10 Correct 2 ms 664 KB Output is correct
11 Correct 2 ms 664 KB Output is correct
12 Correct 2 ms 664 KB Output is correct
13 Correct 2 ms 664 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
15 Correct 2 ms 664 KB Output is correct
16 Correct 2 ms 664 KB Output is correct
17 Correct 2 ms 664 KB Output is correct
18 Correct 2 ms 664 KB Output is correct
19 Correct 2 ms 664 KB Output is correct
20 Correct 2 ms 664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 2 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 2 ms 724 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 2 ms 724 KB Output is correct
31 Correct 2 ms 724 KB Output is correct
32 Correct 2 ms 724 KB Output is correct
33 Correct 2 ms 724 KB Output is correct
34 Correct 2 ms 724 KB Output is correct
35 Correct 2 ms 724 KB Output is correct
36 Correct 2 ms 724 KB Output is correct
37 Correct 2 ms 724 KB Output is correct
38 Correct 2 ms 724 KB Output is correct
39 Correct 2 ms 724 KB Output is correct
40 Correct 2 ms 724 KB Output is correct
41 Correct 2 ms 724 KB Output is correct
42 Correct 2 ms 724 KB Output is correct
43 Correct 2 ms 724 KB Output is correct
44 Correct 2 ms 724 KB Output is correct
45 Correct 2 ms 724 KB Output is correct