답안 #806748

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
806748 2023-08-04T09:31:16 Z CESxRhino Palindrome-Free Numbers (BOI13_numbers) C++14
31.6667 / 100
1 ms 412 KB
#include <bits/stdc++.h>
#define ii pair<int,int>
#define f first
#define s second
#define pb push_back
#define ll long long
#define endl '\n'
using namespace std;
const ll MAXN = 1e18;
ll mod = 1e9 + 7;
ll a[100005];
ll dp[20][2][11][11][2];
string s;
ll Calc(int pos,bool check,int digit1,int digit2,bool start)
{
	if(pos == s.size())
	{
		return 1;
	}
	ll ans = 0;
	if(dp[pos][check][digit1 + 1][digit2 + 1][start] != -1)
	{
		return dp[pos][check][digit1 + 1][digit2 + 1][start];
	}
	ll maxdigit = 0;
	if(check)
	{
		maxdigit = s[pos] - '0';
	}
	else
	{
		maxdigit = 9;
	}
	if(!start)
	{
		for(ll i = 0;i <= maxdigit;i++)
		{
			bool newcheck = check & (i == maxdigit);
			ll newdigit1 = i;
			ll newdigit2 = digit1;
			if(i == 0)
			{
				newdigit1 = -1;
			}
			ll newstart = 0;
			if(i != 0)
			{
				start = 1;
			}
			else
			{
				start = 0;
			}
			ans += Calc(pos + 1,newcheck,newdigit1,newdigit2,start);
		}
	}
	else
	{
		for(ll i = 0;i <= maxdigit;i++)
		{	
			if(i == digit1 or i == digit2)
			{
				continue;
			}
			bool newcheck = check & (i == maxdigit);
			ll newdigit1 = i;
			ll newdigit2 = digit1;
			ans += Calc(pos + 1,newcheck,newdigit1,newdigit2,start);
		}
	}
	return dp[pos][check][digit1 + 1][digit2 + 1][start] = ans;
}
ll ans(ll a)
{
	if(a <= 0)
	{
		return 0;
	}
	s = to_string(a);
	return Calc(0,1,-1,-1,0);
}
void AcSolution()
{
	ll a,b;
	cin >> a >> b;
	cout << ans(b) - ans(a - 1) << endl;
}
signed main()
{
//	freopen("BDIGIT.inp", "r",stdin);
//    freopen("BDIGIT.out", "w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
//	cin >> t;
	while(t--)
	{
		memset(dp,-1,sizeof(dp));
	 	AcSolution();
	}
}


Compilation message

numbers.cpp: In function 'long long int Calc(int, bool, int, int, bool)':
numbers.cpp:16:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  if(pos == s.size())
      |     ~~~~^~~~~~~~~~~
numbers.cpp:45:7: warning: unused variable 'newstart' [-Wunused-variable]
   45 |    ll newstart = 0;
      |       ^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 1 ms 404 KB Output isn't correct
6 Incorrect 1 ms 404 KB Output isn't correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Incorrect 1 ms 340 KB Output isn't correct
12 Incorrect 1 ms 340 KB Output isn't correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Incorrect 1 ms 340 KB Output isn't correct
18 Incorrect 1 ms 340 KB Output isn't correct
19 Incorrect 1 ms 340 KB Output isn't correct
20 Incorrect 1 ms 292 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Incorrect 1 ms 400 KB Output isn't correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Correct 1 ms 400 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Incorrect 1 ms 412 KB Output isn't correct
10 Incorrect 1 ms 404 KB Output isn't correct
11 Incorrect 1 ms 340 KB Output isn't correct
12 Incorrect 1 ms 396 KB Output isn't correct
13 Incorrect 1 ms 400 KB Output isn't correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Incorrect 1 ms 340 KB Output isn't correct
22 Correct 1 ms 340 KB Output is correct
23 Incorrect 1 ms 340 KB Output isn't correct
24 Correct 1 ms 340 KB Output is correct
25 Incorrect 1 ms 340 KB Output isn't correct
26 Incorrect 1 ms 404 KB Output isn't correct
27 Incorrect 1 ms 340 KB Output isn't correct
28 Incorrect 1 ms 340 KB Output isn't correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Incorrect 0 ms 340 KB Output isn't correct
32 Correct 1 ms 340 KB Output is correct
33 Incorrect 1 ms 340 KB Output isn't correct
34 Correct 0 ms 340 KB Output is correct
35 Incorrect 1 ms 340 KB Output isn't correct
36 Incorrect 1 ms 340 KB Output isn't correct
37 Incorrect 1 ms 340 KB Output isn't correct
38 Incorrect 1 ms 340 KB Output isn't correct
39 Incorrect 1 ms 340 KB Output isn't correct
40 Correct 1 ms 340 KB Output is correct
41 Incorrect 1 ms 340 KB Output isn't correct
42 Correct 1 ms 340 KB Output is correct
43 Incorrect 1 ms 400 KB Output isn't correct
44 Incorrect 1 ms 340 KB Output isn't correct
45 Incorrect 1 ms 340 KB Output isn't correct