Submission #38659

# Submission time Handle Problem Language Result Execution time Memory
38659 2018-01-05T13:20:41 Z nibnalin Palindrome-Free Numbers (BOI13_numbers) C++14
100 / 100
0 ms 2196 KB
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

typedef long long int lli;

const lli maxn = 20;

lli memo[maxn][12][12][2][2][2];
string A[2];

inline bool ispal(lli x, lli y, lli z) { return ((y == z) || (x == z)); }

lli DP(lli idx, lli prev, lli pprev, lli less, lli started, lli type)
{
	if(idx == lli(A[type].size())) return 1;
	else if(memo[idx][prev][pprev][less][started][type] != -1) return memo[idx][prev][pprev][less][started][type];
	else
	{
		lli res = 0, val = (less?9:lli(A[type][idx]-'0'));
		for(lli i = 0;i <= val;i++)
		{
			if(ispal(pprev, prev, i)) continue;
			if(!started && !i) res += DP(idx+1, 10, prev, max(less, lli(i < val)), started, type);
			else res += DP(idx+1, i, prev, max(less, lli(i < val)), 1, type);
		}
		return memo[idx][prev][pprev][less][started][type] = res;
	}
}

int main(void)
{
	lli a, b;
	scanf("%lld%lld", &a, &b);
	A[0] = to_string(b), A[1] = to_string(a-1);

	for(lli i = 0;i < maxn;i++)
	{
		for(lli j = 0;j < 11;j++)
		{
			for(lli k = 0;k < 11;k++)
			{
				for(lli l = 0;l < 2;l++)
				{
					for(lli m = 0;m < 2;m++) memo[i][j][k][l][m][0] = memo[i][j][k][l][m][1] = -1;
				}
			}
		}
	}

	lli res = DP(0, 10, 10, 0, 0, 0)-DP(0, 10, 10, 0, 0, 1);
	printf("%lld\n", res);
}

Compilation message

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