답안 #69858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69858 2018-08-21T17:10:49 Z MatheusLealV Palindrome-Free Numbers (BOI13_numbers) C++17
93.75 / 100
6 ms 748 KB
#include <bits/stdc++.h>
#define N 25
using namespace std;
typedef long long ll;

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

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

	while(x > 0)
	{
		ll 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);
	}

	if(a < 0) L = 0;

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

Compilation message

numbers.cpp: In function 'void fill(ll, ll)':
numbers.cpp:25:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < v.size(); i++)
                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 536 KB Output is correct
3 Correct 4 ms 536 KB Output is correct
4 Incorrect 3 ms 536 KB Output isn't correct
5 Incorrect 3 ms 536 KB Output isn't correct
6 Incorrect 3 ms 536 KB Output isn't correct
7 Correct 3 ms 536 KB Output is correct
8 Correct 2 ms 536 KB Output is correct
9 Correct 2 ms 536 KB Output is correct
10 Correct 2 ms 544 KB Output is correct
11 Correct 2 ms 544 KB Output is correct
12 Correct 2 ms 544 KB Output is correct
13 Correct 2 ms 544 KB Output is correct
14 Incorrect 2 ms 544 KB Output isn't correct
15 Incorrect 2 ms 544 KB Output isn't correct
16 Correct 2 ms 588 KB Output is correct
17 Correct 3 ms 588 KB Output is correct
18 Correct 3 ms 588 KB Output is correct
19 Correct 5 ms 588 KB Output is correct
20 Correct 2 ms 660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 660 KB Output is correct
2 Correct 5 ms 660 KB Output is correct
3 Correct 4 ms 660 KB Output is correct
4 Correct 4 ms 660 KB Output is correct
5 Correct 2 ms 660 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 3 ms 748 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 6 ms 748 KB Output is correct
18 Correct 6 ms 748 KB Output is correct
19 Correct 5 ms 748 KB Output is correct
20 Correct 4 ms 748 KB Output is correct
21 Correct 4 ms 748 KB Output is correct
22 Correct 4 ms 748 KB Output is correct
23 Correct 4 ms 748 KB Output is correct
24 Correct 4 ms 748 KB Output is correct
25 Correct 4 ms 748 KB Output is correct
26 Correct 4 ms 748 KB Output is correct
27 Correct 4 ms 748 KB Output is correct
28 Correct 4 ms 748 KB Output is correct
29 Correct 6 ms 748 KB Output is correct
30 Correct 4 ms 748 KB Output is correct
31 Correct 4 ms 748 KB Output is correct
32 Correct 5 ms 748 KB Output is correct
33 Correct 4 ms 748 KB Output is correct
34 Correct 4 ms 748 KB Output is correct
35 Correct 4 ms 748 KB Output is correct
36 Correct 4 ms 748 KB Output is correct
37 Correct 4 ms 748 KB Output is correct
38 Correct 4 ms 748 KB Output is correct
39 Correct 4 ms 748 KB Output is correct
40 Correct 4 ms 748 KB Output is correct
41 Correct 6 ms 748 KB Output is correct
42 Correct 6 ms 748 KB Output is correct
43 Correct 6 ms 748 KB Output is correct
44 Correct 5 ms 748 KB Output is correct
45 Correct 5 ms 748 KB Output is correct