답안 #97244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97244 2019-02-14T15:38:43 Z Shafin666 Palindrome-Free Numbers (BOI13_numbers) C++14
66.6667 / 100
5 ms 512 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<ll, ll>
#define to second
#define cost first
typedef long long ll;
typedef long double ld;
using namespace std;

std::vector<int> num;
int dp[20][12][12][2][2];

int answer(int idx, int a, int b, int noconst, int start) {
	if(idx == (int)num.size()) return 1;
	if(dp[idx][a][b][noconst][start] != -1) return dp[idx][a][b][noconst][start];

	int ret = 0, limit;
	if(noconst) limit = 9; else limit = num[idx];

	for(int i = 0; i <= limit; i++) {
		if(i == a || i == b) continue;
		if(i == 0 && start == 0) ret += answer(idx+1, 10, 10, 1, 0);
		else ret += answer(idx+1, b, i, noconst | (i < num[idx]), 1);
	} return dp[idx][a][b][noconst][start] = ret;
}

int solve(ll n) {
	//if(n < 0) return 0;
	//if(n < 10) return n+1;

	num.clear();
	while(n) {
		num.pb(n%10);
		n /= 10;
	} 
	reverse(num.begin(), num.end());
	memset(dp, -1, sizeof dp);
	return answer(0, 10, 10, 0, 0);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);

	ll a, b;

	cin >> a >> b;
	ll ans = solve(b);
	if(a > 0) ans -= solve(a-1);

	cout << ans << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Incorrect 2 ms 304 KB Output isn't correct
4 Incorrect 3 ms 384 KB Output isn't correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 412 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Incorrect 0 ms 256 KB Output isn't correct
22 Correct 2 ms 384 KB Output is correct
23 Incorrect 3 ms 384 KB Output isn't correct
24 Correct 3 ms 384 KB Output is correct
25 Incorrect 3 ms 384 KB Output isn't correct
26 Incorrect 2 ms 384 KB Output isn't correct
27 Incorrect 3 ms 384 KB Output isn't correct
28 Incorrect 2 ms 384 KB Output isn't correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Incorrect 0 ms 384 KB Output isn't correct
32 Correct 3 ms 384 KB Output is correct
33 Incorrect 3 ms 384 KB Output isn't correct
34 Correct 3 ms 384 KB Output is correct
35 Incorrect 0 ms 384 KB Output isn't correct
36 Incorrect 5 ms 384 KB Output isn't correct
37 Incorrect 2 ms 384 KB Output isn't correct
38 Incorrect 2 ms 384 KB Output isn't correct
39 Incorrect 3 ms 384 KB Output isn't correct
40 Correct 3 ms 384 KB Output is correct
41 Incorrect 3 ms 384 KB Output isn't correct
42 Correct 3 ms 384 KB Output is correct
43 Incorrect 3 ms 384 KB Output isn't correct
44 Incorrect 3 ms 384 KB Output isn't correct
45 Incorrect 3 ms 384 KB Output isn't correct