답안 #97251

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97251 2019-02-14T15:47:57 Z Shafin666 Palindrome-Free Numbers (BOI13_numbers) C++14
66.6667 / 100
5 ms 384 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;
ll dp[20][12][12][2][2];
string str;

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

	ll ret = 0, limit;
	if(noconst) limit = 9; else limit = str[idx]-48; //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 < limit), 1);
	} return dp[idx][a][b][noconst][start] = ret;
}

int solve(ll n) {
	//if(n < 0) return 0;
	//if(n < 10) return n+1;
	str = to_string(n);
//	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 3 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 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 2 ms 356 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 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 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 3 ms 384 KB Output isn't correct
3 Incorrect 3 ms 384 KB Output isn't correct
4 Incorrect 2 ms 384 KB Output isn't correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 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 3 ms 384 KB Output is correct
11 Correct 3 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 2 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Incorrect 5 ms 384 KB Output isn't correct
22 Correct 3 ms 256 KB Output is correct
23 Incorrect 0 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 3 ms 384 KB Output isn't correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Incorrect 2 ms 384 KB Output isn't correct
32 Correct 3 ms 384 KB Output is correct
33 Incorrect 2 ms 384 KB Output isn't correct
34 Correct 3 ms 384 KB Output is correct
35 Incorrect 3 ms 384 KB Output isn't correct
36 Incorrect 2 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 2 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 2 ms 384 KB Output isn't correct
45 Incorrect 1 ms 384 KB Output isn't correct