Submission #37486

# Submission time Handle Problem Language Result Execution time Memory
37486 2017-12-26T02:48:39 Z 14kg Palindrome-Free Numbers (BOI13_numbers) C++11
1.66667 / 100
0 ms 2452 KB
#include <stdio.h>

bool check[11][11][19];
long long d[11][11][19];

long long f(int x, int y, int len) {
	if (len == 0) return 1;

	if (!check[x][y][len]) {
		check[x][y][len] = true;

		if (x == 10 && y == 10) {
			for (int i = 1; i < 10; i++) d[x][y][len] += f(10, i, len - 1);
			d[x][y][len] += f(10, 10, len - 1);
		}
		else if (x == 10) {
			for (int i = 0; i < 10; i++)
				if (i != y) d[x][y][len] += f(y, i, len - 1);
		}
		else {
			for (int i = 0; i < 10; i++) {
				if (i == x || i == y) continue;
				d[x][y][len] += f(y, i, len - 1);
			}
		}
	} return d[x][y][len];
}

long long out(long long x) {
	long long sum = 0, check_m;
	int len = 0, temp[19] = { 0 }, in[19] = { 0 };
	
	while (x) temp[++len] = x % 10, x /= 10;
	for (int i = 1; i <= len; i++) in[len - i + 1] = temp[i];

	in[0] = 10;
	for (int i = len; i >= 2; i--) {
		check_m = 1;
		for (int j = 2; j < i; j++)
			if (in[j - 2] == in[j] || in[j - 1] == in[j]) check_m = 0;

		for (int j = 0; j < in[i]; j++)
			if (j != in[i - 1] && j != in[i - 2]) sum += f(in[i - 1], j, len - i)*check_m;
	}
	for (int i = 1; i < in[1]; i++) sum += f(10, i, len - 1);
	sum += f(10, 10, len - 1);

	return sum;
}

int main() {
	long long x, y, sum;

	scanf("%lld %lld", &x, &y);

	sum = out(y);
	if (x > 0) sum -= out(x - 1);

	printf("%lld", sum + 1);;
}

Compilation message

numbers.cpp: In function 'int main()':
numbers.cpp:54:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld", &x, &y);
                            ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 1132 KB Output isn't correct
2 Incorrect 0 ms 1132 KB Output isn't correct
3 Incorrect 0 ms 1132 KB Output isn't correct
4 Incorrect 0 ms 1132 KB Output isn't correct
5 Runtime error 0 ms 1132 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 0 ms 1132 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Incorrect 0 ms 1132 KB Output isn't correct
8 Incorrect 0 ms 1132 KB Output isn't correct
9 Incorrect 0 ms 1132 KB Output isn't correct
10 Incorrect 0 ms 1132 KB Output isn't correct
11 Incorrect 0 ms 1132 KB Output isn't correct
12 Incorrect 0 ms 1132 KB Output isn't correct
13 Incorrect 0 ms 1132 KB Output isn't correct
14 Incorrect 0 ms 1132 KB Output isn't correct
15 Incorrect 0 ms 1132 KB Output isn't correct
16 Incorrect 0 ms 1132 KB Output isn't correct
17 Incorrect 0 ms 1132 KB Output isn't correct
18 Runtime error 0 ms 2452 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Incorrect 0 ms 1132 KB Output isn't correct
20 Incorrect 0 ms 1132 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 1132 KB Output isn't correct
2 Incorrect 0 ms 1132 KB Output isn't correct
3 Incorrect 0 ms 1132 KB Output isn't correct
4 Incorrect 0 ms 1132 KB Output isn't correct
5 Incorrect 0 ms 1132 KB Output isn't correct
6 Incorrect 0 ms 1132 KB Output isn't correct
7 Incorrect 0 ms 1132 KB Output isn't correct
8 Correct 0 ms 1132 KB Output is correct
9 Incorrect 0 ms 1132 KB Output isn't correct
10 Incorrect 0 ms 1132 KB Output isn't correct
11 Incorrect 0 ms 1132 KB Output isn't correct
12 Incorrect 0 ms 1132 KB Output isn't correct
13 Incorrect 0 ms 1132 KB Output isn't correct
14 Incorrect 0 ms 1132 KB Output isn't correct
15 Incorrect 0 ms 1132 KB Output isn't correct
16 Incorrect 0 ms 1132 KB Output isn't correct
17 Incorrect 0 ms 1132 KB Output isn't correct
18 Incorrect 0 ms 1132 KB Output isn't correct
19 Incorrect 0 ms 1132 KB Output isn't correct
20 Incorrect 0 ms 1132 KB Output isn't correct
21 Incorrect 0 ms 1132 KB Output isn't correct
22 Incorrect 0 ms 1132 KB Output isn't correct
23 Incorrect 0 ms 1132 KB Output isn't correct
24 Incorrect 0 ms 1132 KB Output isn't correct
25 Incorrect 0 ms 1132 KB Output isn't correct
26 Incorrect 0 ms 1132 KB Output isn't correct
27 Incorrect 0 ms 1132 KB Output isn't correct
28 Incorrect 0 ms 1132 KB Output isn't correct
29 Incorrect 0 ms 1132 KB Output isn't correct
30 Incorrect 0 ms 1132 KB Output isn't correct
31 Incorrect 0 ms 1132 KB Output isn't correct
32 Incorrect 0 ms 1132 KB Output isn't correct
33 Incorrect 0 ms 1132 KB Output isn't correct
34 Incorrect 0 ms 1132 KB Output isn't correct
35 Incorrect 0 ms 1132 KB Output isn't correct
36 Incorrect 0 ms 1132 KB Output isn't correct
37 Incorrect 0 ms 1132 KB Output isn't correct
38 Incorrect 0 ms 1132 KB Output isn't correct
39 Incorrect 0 ms 1132 KB Output isn't correct
40 Incorrect 0 ms 1132 KB Output isn't correct
41 Incorrect 0 ms 1132 KB Output isn't correct
42 Incorrect 0 ms 1132 KB Output isn't correct
43 Incorrect 0 ms 1132 KB Output isn't correct
44 Incorrect 0 ms 1132 KB Output isn't correct
45 Incorrect 0 ms 1132 KB Output isn't correct