답안 #546069

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
546069 2022-04-06T08:27:16 Z MilosMilutinovic Palindrome-Free Numbers (BOI13_numbers) C++14
31.25 / 100
1 ms 340 KB
/* idea is correct, find bug */
#include <stdio.h>
#include <string.h>

#define L	18
#define K	10

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

	l = 0;
	while (n > 0) {
		dd[l++] = n % 10;
		n /= 10;
	}
	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;
	for (i = 1; i <= dd[l - 1]; i++)
		 for (j = 0; j < (i == dd[l - 1] ? dd[l - 2] + 1 : K); j++)
			if (i != j || (i == 0))
				dp[l - 2][j][i][(i == dd[l - 1] && j == dd[l - 2]) ? 1 : 0] = 1;
	for (i = l - 3; i >= 0; i--)
		for (d = 0; d < K; d++)
			for (d_ = 0; d_ < K; d_++)
				if (d != d_)
					for (dd_ = 0; dd_ < K; dd_++)
						if (d != dd_) {
							dp[i][d][d_][0] += dp[i + 1][d_][dd_][0];
							if (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];
						}
	long long ans = 0;
	for (d = 0; d < K; d++)
		for (d_ = 0; d_ < K; d_++)
				ans += dp[0][d][d_][0];
	return ans;
}

long long calc(long long n) {
	long long ans;
	long long d;

	ans = solve(n), d = 9;
	while (d < n) {
		ans += solve(d);
		d = d * 10 + 9;
	}
	return ans;
}

int brute_force(int n) {
	static int dd[L + 1];
	int i, j, l, ans;

	ans = 0;
	for (i = 1; i < n; i++) {
		l = 0;

		int x = i;
		while (x > 0) {
			dd[l++] = x % 10;
			x /= 10;
		}

		bool ok = true;
		for (j = 1; j < l; j++)
			ok &= (dd[j] != dd[j - 1] && (j == 1 || (dd[j - 2] != dd[j])));
		ans += ok;
	}
	return ans;
}

int main() {
	long long l, r;

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

Compilation message

numbers.cpp: In function 'int main()':
numbers.cpp:84:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |  scanf("%lld%lld", &l, &r);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 292 KB Output isn't correct
2 Incorrect 1 ms 288 KB Output isn't correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Incorrect 1 ms 292 KB Output isn't correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Incorrect 1 ms 212 KB Output isn't correct
8 Incorrect 1 ms 212 KB Output isn't correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Incorrect 1 ms 212 KB Output isn't correct
15 Incorrect 1 ms 212 KB Output isn't correct
16 Correct 1 ms 288 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Incorrect 1 ms 212 KB Output isn't correct
20 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 288 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 1 ms 292 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 1 ms 296 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 292 KB Output is correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Incorrect 1 ms 288 KB Output isn't correct
18 Incorrect 1 ms 212 KB Output isn't correct
19 Incorrect 1 ms 212 KB Output isn't correct
20 Incorrect 1 ms 212 KB Output isn't correct
21 Incorrect 1 ms 212 KB Output isn't correct
22 Incorrect 1 ms 212 KB Output isn't correct
23 Incorrect 1 ms 292 KB Output isn't correct
24 Incorrect 1 ms 212 KB Output isn't correct
25 Incorrect 1 ms 292 KB Output isn't correct
26 Incorrect 1 ms 212 KB Output isn't correct
27 Incorrect 1 ms 212 KB Output isn't correct
28 Incorrect 1 ms 292 KB Output isn't correct
29 Incorrect 1 ms 212 KB Output isn't correct
30 Incorrect 1 ms 212 KB Output isn't correct
31 Incorrect 1 ms 296 KB Output isn't correct
32 Incorrect 1 ms 292 KB Output isn't correct
33 Incorrect 1 ms 212 KB Output isn't correct
34 Incorrect 1 ms 212 KB Output isn't correct
35 Incorrect 1 ms 288 KB Output isn't correct
36 Incorrect 1 ms 212 KB Output isn't correct
37 Incorrect 1 ms 212 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 288 KB Output isn't correct
41 Incorrect 1 ms 212 KB Output isn't correct
42 Incorrect 1 ms 292 KB Output isn't correct
43 Incorrect 1 ms 212 KB Output isn't correct
44 Incorrect 1 ms 212 KB Output isn't correct
45 Incorrect 1 ms 296 KB Output isn't correct