Submission #69856

# Submission time Handle Problem Language Result Execution time Memory
69856 2018-08-21T17:06:46 Z MatheusLealV Palindrome-Free Numbers (BOI13_numbers) C++17
35 / 100
4 ms 1120 KB
#include <bits/stdc++.h>
#define N 20
using namespace std;
typedef long long ll;

int a, b, A[N], B[N], sz[2];

void fill(int x, int t)
{
	vector<int> v;

	while(x > 0)
	{
		int r = x % 10;

		v.push_back(r);

		x /= 10;
	}

	reverse(v.begin(), v.end());

	sz[t] = v.size();

	for(int i = 0; i < v.size(); i++)
		if(!t) A[i+1] = v[i];
		else B[i+1] = v[i];
}

// F = 1, O NUMERO JÁ É ESTRITAMENTE MENOR
//F = 0, O NUMERO É EXATAMENTE IGUAL

ll dp[N][13][13][2];

ll solveA(int i, int a, int b, int f)
{
	if(i > sz[0]) return 1;

	if(dp[i][a+1][b+1][f] != -1) return dp[i][a+1][b+1][f];

	ll ans = 0;

	for(int k = 0; k < 10; k++)
	{
		if((i == 1 and !k) or k == a or k == b) continue;

		if(f == 1) ans += solveA(i + 1, k, a, f);

		else
		{
			if(k < A[i]) ans += solveA(i + 1, k, a, 1);

			else if(k == A[i]) ans += solveA(i + 1, k, a, 0);
		}
	}

	return dp[i][a+1][b+1][f] = ans;
}

int t;

ll solveA2(int i, int a, int b, int f)
{
	if(i > t) return 1;

	if(dp[i][a+1][b+1][f] != -1) return dp[i][a+1][b+1][f];

	ll ans = 0;

	for(int k = 0; k < 10; k++)
	{
		if((i == 1 and !k) or k == a or k == b) continue;

		ans += solveA2(i + 1, k, a, f);
	}

	return dp[i][a+1][b+1][f] = ans;
}

int main()
{
	cin>>a>>b;

	a--;

	fill(a, 0);

	memset(dp, -1, sizeof dp);

	ll L = solveA(1, -1, -1, 0);

	for(int T = 1; T < sz[0]; T++)
	{
		t = T;

		memset(dp, -1, sizeof dp);

		L += solveA2(1, -1, -1, 0);
	}

	memset(dp, -1, sizeof dp);

	fill(b, 0);

	ll R = solveA(1, -1, -1, 0);

	for(int T = 1; T < sz[0]; T++)
	{
		t = T;

		memset(dp, -1, sizeof dp);

		R += solveA2(1, -1, -1, 0);
	}

	cout<<R - L<<"\n";
}

Compilation message

numbers.cpp: In function 'void fill(int, int)':
numbers.cpp:25:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < v.size(); i++)
                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Incorrect 4 ms 676 KB Output isn't correct
4 Incorrect 3 ms 676 KB Output isn't correct
5 Incorrect 2 ms 744 KB Output isn't correct
6 Incorrect 3 ms 744 KB Output isn't correct
7 Correct 2 ms 744 KB Output is correct
8 Correct 3 ms 744 KB Output is correct
9 Correct 2 ms 804 KB Output is correct
10 Correct 2 ms 804 KB Output is correct
11 Correct 2 ms 804 KB Output is correct
12 Correct 3 ms 828 KB Output is correct
13 Correct 2 ms 832 KB Output is correct
14 Incorrect 2 ms 832 KB Output isn't correct
15 Incorrect 3 ms 964 KB Output isn't correct
16 Correct 4 ms 964 KB Output is correct
17 Correct 2 ms 964 KB Output is correct
18 Incorrect 3 ms 964 KB Output isn't correct
19 Incorrect 3 ms 964 KB Output isn't correct
20 Correct 3 ms 964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 964 KB Output is correct
2 Incorrect 3 ms 964 KB Output isn't correct
3 Incorrect 2 ms 1016 KB Output isn't correct
4 Incorrect 3 ms 1016 KB Output isn't correct
5 Correct 4 ms 1016 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
7 Correct 2 ms 1016 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
9 Correct 3 ms 1016 KB Output is correct
10 Correct 3 ms 1016 KB Output is correct
11 Correct 2 ms 1016 KB Output is correct
12 Correct 2 ms 1016 KB Output is correct
13 Correct 4 ms 1016 KB Output is correct
14 Correct 3 ms 1016 KB Output is correct
15 Correct 3 ms 1016 KB Output is correct
16 Incorrect 3 ms 1016 KB Output isn't correct
17 Incorrect 4 ms 1016 KB Output isn't correct
18 Incorrect 3 ms 1016 KB Output isn't correct
19 Incorrect 3 ms 1016 KB Output isn't correct
20 Incorrect 3 ms 1016 KB Output isn't correct
21 Incorrect 2 ms 1016 KB Output isn't correct
22 Incorrect 3 ms 1016 KB Output isn't correct
23 Incorrect 2 ms 1016 KB Output isn't correct
24 Incorrect 3 ms 1016 KB Output isn't correct
25 Incorrect 2 ms 1120 KB Output isn't correct
26 Incorrect 3 ms 1120 KB Output isn't correct
27 Incorrect 2 ms 1120 KB Output isn't correct
28 Incorrect 4 ms 1120 KB Output isn't correct
29 Incorrect 2 ms 1120 KB Output isn't correct
30 Incorrect 4 ms 1120 KB Output isn't correct
31 Incorrect 3 ms 1120 KB Output isn't correct
32 Incorrect 3 ms 1120 KB Output isn't correct
33 Incorrect 2 ms 1120 KB Output isn't correct
34 Incorrect 3 ms 1120 KB Output isn't correct
35 Incorrect 4 ms 1120 KB Output isn't correct
36 Incorrect 3 ms 1120 KB Output isn't correct
37 Incorrect 3 ms 1120 KB Output isn't correct
38 Incorrect 3 ms 1120 KB Output isn't correct
39 Incorrect 3 ms 1120 KB Output isn't correct
40 Incorrect 3 ms 1120 KB Output isn't correct
41 Incorrect 3 ms 1120 KB Output isn't correct
42 Incorrect 4 ms 1120 KB Output isn't correct
43 Incorrect 4 ms 1120 KB Output isn't correct
44 Incorrect 3 ms 1120 KB Output isn't correct
45 Incorrect 3 ms 1120 KB Output isn't correct