Submission #546048

# Submission time Handle Problem Language Result Execution time Memory
546048 2022-04-06T07:24:44 Z MilosMilutinovic Palindrome-Free Numbers (BOI13_numbers) C++14
12.0833 / 100
1 ms 292 KB
/* idea is correct, find bug */
#include <stdio.h>
#include <string.h>

#define L	18
#define K	10

long long solve(int n) {
	static int dd[L + 1];
	static long long dp[L + 1][K][K][2];
	int l, i, d, d_, dd_;

	l = 0;
	while (n > 0) {
		dd[l++] = n % 10;
		n /= 10;
	}
//	for (i = 0; i < l; i++)
//		printf("%d", dd[i]);
//	printf("\n");
	for (i = 0; i < L + 1; i++)
		for (d = 0; d < K; d++)
			for (d_ = 0; d_ < K; d_++)
				dp[i][d][d_][0] = dp[i][d][d_][1] = 0;
	dp[l][0][0][1] = 1;
	for (i = l - 1; i >= 0; i--)
		for (d = 0; d < K; d++)
			for (d_ = 0; d_ < K; d_++)
				if (d != d_)
					for (dd_ = 0; dd_ < K; dd_++) {
						dp[i][d][d_][0] += dp[i + 1][d_][dd_][0];
						if (i < l - 1 || d < dd[i])
							dp[i][d][d_][0] += dp[i + 1][d_][dd_][1];
						if (d == dd[i])
							dp[i][d][d_][1] += dp[i + 1][d_][dd_][1];
					}
//	for (i = l - 1; i >= 0; i--)
//		for (d = 0; d < K; d++)
//			for (d_ = 0; d_ < K; d_++)
//				printf("dp[%d][%d][%d][0]: %d\n", i, d, d_, dp[i][d][d_][0]);
	long long ans = 0;
	for (d = 0; d < K; d++)
		for (d_ = 0; d_ < K; d_++)
				ans += dp[0][d][d_][0];
	return ans;
}

int main() {
	long long l, r;

	scanf("%lld%lld", &l, &r);
	printf("%lld\n", solve(r + 1) - solve(l));
	return 0;
}

Compilation message

numbers.cpp: In function 'int main()':
numbers.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |  scanf("%lld%lld", &l, &r);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Incorrect 1 ms 288 KB Output isn't correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Correct 0 ms 284 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Incorrect 1 ms 212 KB Output isn't correct
9 Incorrect 0 ms 288 KB Output isn't correct
10 Incorrect 0 ms 292 KB Output isn't correct
11 Incorrect 0 ms 212 KB Output isn't correct
12 Incorrect 1 ms 292 KB Output isn't correct
13 Incorrect 1 ms 212 KB Output isn't correct
14 Incorrect 1 ms 212 KB Output isn't correct
15 Incorrect 1 ms 212 KB Output isn't correct
16 Incorrect 0 ms 212 KB Output isn't correct
17 Incorrect 0 ms 288 KB Output isn't correct
18 Incorrect 0 ms 212 KB Output isn't correct
19 Incorrect 0 ms 288 KB Output isn't correct
20 Incorrect 1 ms 288 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Incorrect 0 ms 288 KB Output isn't correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Incorrect 0 ms 284 KB Output isn't correct
5 Incorrect 1 ms 284 KB Output isn't correct
6 Incorrect 0 ms 212 KB Output isn't correct
7 Incorrect 1 ms 292 KB Output isn't correct
8 Incorrect 1 ms 212 KB Output isn't correct
9 Incorrect 1 ms 288 KB Output isn't correct
10 Incorrect 1 ms 212 KB Output isn't correct
11 Incorrect 0 ms 292 KB Output isn't correct
12 Incorrect 1 ms 212 KB Output isn't correct
13 Incorrect 1 ms 212 KB Output isn't correct
14 Incorrect 1 ms 212 KB Output isn't correct
15 Incorrect 1 ms 212 KB Output isn't correct
16 Incorrect 1 ms 212 KB Output isn't correct
17 Incorrect 1 ms 212 KB Output isn't correct
18 Correct 0 ms 212 KB Output is correct
19 Incorrect 0 ms 212 KB Output isn't correct
20 Correct 0 ms 212 KB Output is correct
21 Incorrect 1 ms 212 KB Output isn't correct
22 Incorrect 1 ms 288 KB Output isn't correct
23 Incorrect 1 ms 288 KB Output isn't correct
24 Correct 0 ms 212 KB Output is correct
25 Incorrect 1 ms 212 KB Output isn't correct
26 Incorrect 1 ms 284 KB Output isn't correct
27 Incorrect 1 ms 212 KB Output isn't correct
28 Incorrect 1 ms 212 KB Output isn't correct
29 Correct 0 ms 212 KB Output is correct
30 Incorrect 0 ms 212 KB Output isn't correct
31 Incorrect 0 ms 212 KB Output isn't correct
32 Incorrect 0 ms 212 KB Output isn't correct
33 Incorrect 0 ms 212 KB Output isn't correct
34 Incorrect 1 ms 212 KB Output isn't correct
35 Incorrect 0 ms 292 KB Output isn't correct
36 Incorrect 0 ms 212 KB Output isn't correct
37 Incorrect 0 ms 288 KB Output isn't correct
38 Incorrect 1 ms 212 KB Output isn't correct
39 Incorrect 1 ms 212 KB Output isn't correct
40 Incorrect 1 ms 212 KB Output isn't correct
41 Incorrect 1 ms 284 KB Output isn't correct
42 Correct 1 ms 212 KB Output is correct
43 Incorrect 0 ms 212 KB Output isn't correct
44 Incorrect 0 ms 212 KB Output isn't correct
45 Incorrect 0 ms 212 KB Output isn't correct