Submission #98358

# Submission time Handle Problem Language Result Execution time Memory
98358 2019-02-22T18:31:23 Z luciocf Palindrome-Free Numbers (BOI13_numbers) C++14
96.25 / 100
9 ms 544 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 20;

typedef long long ll;

ll dp[maxn][10][10][3][3];

string a, b;

ll solve(int pos, int d1, int d2, int m1, int m2)
{
	if (pos == b.size()) return 0;
	if (dp[pos][d1][d2][m1][m2] != -1) return dp[pos][d1][d2][m1][m2];

	ll ans = 0LL;
	for (int i = 0; i <= 9; i++)
	{
		if ((!i && !pos) || (i == d1 && pos >= 2) || (i == d2 && pos >= 1)) continue;

		int n1 = 2;
		if (!m1) n1 = 0;
		else if (m1 == 1) n1 = 1;
		else if (i < (int)a[pos]-'0') n1 = 0;
		else if (i > (int)a[pos]-'0') n1 = 1;

		int n2 = 2;
		if (!m2) n2 = 0;
		else if (m2 == 1) n2 = 1;
		else if (i < (int)b[pos]-'0') n2 = 0;
		else if (i > (int)b[pos]-'0') n2 = 1;

		int add = 0;

		if (a.size() == b.size() && pos == a.size()-1)
		{
			if (n1 && n2 != 1) add = 1;
			else add = 0;
		}
		else if (pos == a.size()-1 && n1) add = 1;
		else if (pos > a.size()-1 && pos < b.size()-1) add = 1;
		else if (pos == b.size()-1 && n2 != 1) add = 1;

		ans += (ll)add+solve(pos+1, d2, i, n1, n2);
	}

	return dp[pos][d1][d2][m1][m2] = ans;
}

int main(void)
{
	memset(dp, -1, sizeof dp);

	cin >> a >> b;

	cout << solve(0, 0, 0, 2, 2) << "\n";
}

Compilation message

numbers.cpp: In function 'll solve(int, int, int, int, int)':
numbers.cpp:15:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (pos == b.size()) return 0;
      ~~~~^~~~~~~~~~~
numbers.cpp:37:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (a.size() == b.size() && pos == a.size()-1)
                               ~~~~^~~~~~~~~~~~~
numbers.cpp:42:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   else if (pos == a.size()-1 && n1) add = 1;
            ~~~~^~~~~~~~~~~~~
numbers.cpp:43:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   else if (pos > a.size()-1 && pos < b.size()-1) add = 1;
            ~~~~^~~~~~~~~~~~
numbers.cpp:43:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   else if (pos > a.size()-1 && pos < b.size()-1) add = 1;
                                ~~~~^~~~~~~~~~~~
numbers.cpp:44:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   else if (pos == b.size()-1 && n2 != 1) add = 1;
            ~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Incorrect 2 ms 512 KB Output isn't correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 544 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Incorrect 3 ms 512 KB Output isn't correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Incorrect 2 ms 512 KB Output isn't correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 2 ms 544 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 4 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 544 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 3 ms 520 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 2 ms 512 KB Output is correct
39 Correct 3 ms 512 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 3 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 9 ms 512 KB Output is correct
44 Correct 3 ms 484 KB Output is correct
45 Correct 3 ms 512 KB Output is correct