Submission #849873

# Submission time Handle Problem Language Result Execution time Memory
849873 2023-09-15T13:52:28 Z NK_ Palindrome-Free Numbers (BOI13_numbers) C++17
Compilation error
0 ms 0 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
 
using namespace std;
 
#define nl '\n'
#define pb push_back
#define pf push_front
 
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
 
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
 
using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;
 
using db = long double;
 
template<class T> using pq = priority_queue<T, V<T>, less<T>>;
 
const int MOD = 1e9 + 7;
const ll INFL = ll(1e17);
const int LG = 19;

using H = array<int, 6>;

int main() {
	cin.tie(0)->sync_with_stdio(0);
 
	string L, R; cin >> L >> R;

	while(sz(L) < sz(R)) L = "0"+L;

	ll ans = 0;
	if (L == string(sz(L), '0')) {
		L.back() = '1';
		ans = 1;
	}

	umap<H, ll> MEMO;
	function<ll(int, int, int, int, int, int)> DP = [&](int i, int gl, int lr, int nonz, int a, int b) {
		H cur = {i, gl, lr, nonz, a, b};
		if (MEMO.find(cur) != MEMO.end()) return MEMO[cur];
		// cout << i << " " << gl << " " << lr << " " << nonz << " " << a << " " << b << endl;

		if (i == sz(L)) {
			// cout << a << " " << b << endl;
			return MEMO[cur] = 1LL;
		}

		ll RES = 0;
		for(int c = 0; c <= 9; c++) {

			int ngl = (gl || c > (L[i]-'0'));
			int nlr = (lr || c < (R[i]-'0'));
			// cout << L[i] << " " << c << " " << R[i] << endl;

			if (!gl && c < (L[i]-'0')) continue;
			if (!lr && c > (R[i]-'0')) continue;

			if (!nonz && c == 0) {
				RES += DP(i+1, ngl, nlr, 0, -2, -1);
				continue;
			}	

			if (a == c || b == c) continue;

			RES += DP(i+1, ngl, nlr, 1, b, c);
		}		

		return MEMO[cur] = RES;
	};


 	
	ans += DP(0, 0, 0, 0, -2, -1);

	cout << ans << nl;


	exit(0-0);
} 

/*
123456789 987654321
*/

Compilation message

numbers.cpp: In function 'int main()':
numbers.cpp:48:2: error: 'umap' was not declared in this scope
   48 |  umap<H, ll> MEMO;
      |  ^~~~
numbers.cpp:48:8: error: expected primary-expression before ',' token
   48 |  umap<H, ll> MEMO;
      |        ^
numbers.cpp:48:12: error: expected primary-expression before '>' token
   48 |  umap<H, ll> MEMO;
      |            ^
numbers.cpp:48:14: error: 'MEMO' was not declared in this scope
   48 |  umap<H, ll> MEMO;
      |              ^~~~
numbers.cpp:80:2: error: conversion from 'main()::<lambda(int, int, int, int, int, int)>' to non-scalar type 'std::function<long long int(int, int, int, int, int, int)>' requested
   80 |  };
      |  ^