Submission #110712

# Submission time Handle Problem Language Result Execution time Memory
110712 2019-05-12T06:36:52 Z ckodser Palindrome-Free Numbers (BOI13_numbers) C++14
72.5 / 100
3 ms 408 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 19;
ll dp[N], dp2[N], dp3[N];
ll Get(ll r)
{
	if (r < 0) return (0);
	if (r <= 9) return (r + 1);
	ll m = r, len = 0;
	int A[N];
	while (m)
		A[len ++] = m % 10, m /= 10;
	reverse(A, A + len);
	ll res = dp[len - 1];

	for (int i = 0; i < len; i++)
	{
		for (int j = 0; j < A[i]; j++)
		{
			if (i > 0 && j == A[i - 1])
				continue;
			if (i > 1 && j == A[i - 2])
				continue;
			if (i == 0)
				res += dp2[len - 1];
			else
				res += dp3[len - i - 1];
		}
		if (i > 0 && A[i] == A[i - 1])
			return (res);
		if (i > 1 && A[i] == A[i - 2])
			return (res);
	}
	if (A[len - 1] != A[len - 2] && (len == 2 || (A[len - 1] != A[len - 3])))
		res ++;
	return (res);
}
int main()
{
	dp[1] = 10;
	for (int i = 2; i < N; i++)
		dp[i] = dp[i - 1] * 8 + 11;

	dp2[0] = 1;
	dp2[1] = 9;
	for (int i = 2; i < N; i++)
		dp2[i] = dp2[i - 1] * 8;

	dp3[0] = 1;
	dp3[1] = 8;
	for (int i = 2; i < N; i++)
		dp3[i] = dp3[i - 1] * 8;

	ll l, r;
	scanf("%lld%lld", &l, &r);
	return !printf("%lld\n", Get(r) - Get(l - 1));
}

Compilation message

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