Submission #806751

# Submission time Handle Problem Language Result Execution time Memory
806751 2023-08-04T09:33:34 Z CESxRhino Palindrome-Free Numbers (BOI13_numbers) C++17
Compilation error
0 ms 0 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(ll pos,bool check,ll digit1,ll digit2,bool start)
{
	if(pos == s.size())
	{
		return 1;
	}
	ll ans = 0;
	if(dp[pos][check][digit1][digit2][start] != -1)
	{
		return dp[pos][check][digit1][digit2][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;
	}	
	memset(dp,-1,sizeof(dp));
	a = to_string(a);
	return Calc(0,0,-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(long long int, bool, long long int, long long int, bool)':
numbers.cpp:16:9: warning: comparison of integer expressions of different signedness: 'long long 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;
      |       ^~~~~~~~
numbers.cpp: In function 'long long int ans(long long int)':
numbers.cpp:80:15: error: cannot convert 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'long long int' in assignment
   80 |  a = to_string(a);
      |      ~~~~~~~~~^~~
      |               |
      |               std::string {aka std::__cxx11::basic_string<char>}