Submission #49168

# Submission time Handle Problem Language Result Execution time Memory
49168 2018-05-23T04:06:54 Z aome Palindrome-Free Numbers (BOI13_numbers) C++17
100 / 100
3 ms 1028 KB
#include <bits/stdc++.h>

using namespace std;

int A[20], B[20];
long long f[20][11][11][2][2][2];

long long calc(int p, int prv1, int prv2, bool oka, bool okb, bool nonzero) {
	long long &ret = f[p][prv1][prv2][oka][okb][nonzero];
	if (ret != -1) return ret;
	if (p == 18) return 1;
	ret = 0;
	int l, r;
	l = 0, r = 9;
	if (!oka) l = A[p];
	if (!okb) r = B[p];
	for (int i = l; i <= r; ++i) {
		if (i == prv1 || i == prv2) continue;
		if (!i && !nonzero) {
			ret += calc(p + 1, 10, 10, oka | (i > l), okb | (i < r), 0);
		} 
		else {
			ret += calc(p + 1, i, prv1, oka | (i > l), okb | (i < r), 1);
		} 
	} 
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	long long a, b; cin >> a >> b;
	for (int i = 0; i < 18; ++i) A[17 - i] = a % 10, a /= 10;
	for (int i = 0; i < 18; ++i) B[17 - i] = b % 10, b /= 10;
	memset(f, -1, sizeof f);
	cout << calc(0, 10, 10, 0, 0, 0);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 616 KB Output is correct
3 Correct 3 ms 616 KB Output is correct
4 Correct 3 ms 628 KB Output is correct
5 Correct 3 ms 676 KB Output is correct
6 Correct 2 ms 708 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 3 ms 896 KB Output is correct
9 Correct 3 ms 896 KB Output is correct
10 Correct 2 ms 896 KB Output is correct
11 Correct 2 ms 896 KB Output is correct
12 Correct 2 ms 896 KB Output is correct
13 Correct 2 ms 896 KB Output is correct
14 Correct 2 ms 896 KB Output is correct
15 Correct 2 ms 896 KB Output is correct
16 Correct 2 ms 896 KB Output is correct
17 Correct 2 ms 896 KB Output is correct
18 Correct 2 ms 896 KB Output is correct
19 Correct 2 ms 896 KB Output is correct
20 Correct 2 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 896 KB Output is correct
2 Correct 3 ms 896 KB Output is correct
3 Correct 3 ms 896 KB Output is correct
4 Correct 2 ms 896 KB Output is correct
5 Correct 2 ms 960 KB Output is correct
6 Correct 3 ms 960 KB Output is correct
7 Correct 3 ms 960 KB Output is correct
8 Correct 3 ms 960 KB Output is correct
9 Correct 2 ms 976 KB Output is correct
10 Correct 3 ms 976 KB Output is correct
11 Correct 3 ms 976 KB Output is correct
12 Correct 2 ms 976 KB Output is correct
13 Correct 2 ms 992 KB Output is correct
14 Correct 2 ms 992 KB Output is correct
15 Correct 2 ms 992 KB Output is correct
16 Correct 2 ms 992 KB Output is correct
17 Correct 2 ms 992 KB Output is correct
18 Correct 3 ms 992 KB Output is correct
19 Correct 2 ms 992 KB Output is correct
20 Correct 3 ms 992 KB Output is correct
21 Correct 2 ms 996 KB Output is correct
22 Correct 2 ms 996 KB Output is correct
23 Correct 3 ms 996 KB Output is correct
24 Correct 2 ms 996 KB Output is correct
25 Correct 2 ms 996 KB Output is correct
26 Correct 2 ms 996 KB Output is correct
27 Correct 3 ms 996 KB Output is correct
28 Correct 2 ms 996 KB Output is correct
29 Correct 3 ms 996 KB Output is correct
30 Correct 2 ms 996 KB Output is correct
31 Correct 2 ms 996 KB Output is correct
32 Correct 3 ms 996 KB Output is correct
33 Correct 3 ms 996 KB Output is correct
34 Correct 3 ms 996 KB Output is correct
35 Correct 3 ms 996 KB Output is correct
36 Correct 3 ms 996 KB Output is correct
37 Correct 3 ms 996 KB Output is correct
38 Correct 3 ms 1000 KB Output is correct
39 Correct 3 ms 1004 KB Output is correct
40 Correct 3 ms 1008 KB Output is correct
41 Correct 3 ms 1012 KB Output is correct
42 Correct 3 ms 1016 KB Output is correct
43 Correct 2 ms 1020 KB Output is correct
44 Correct 3 ms 1024 KB Output is correct
45 Correct 2 ms 1028 KB Output is correct