Submission #67524770


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

const char nl = '\n';
const char sp = ' ';
using u64 = unsigned long long;
using ll = long long;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<ll>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using si = unordered_set<int>;
using sl = unordered_set<ll>;
using tsi = set<int>;
using tsl = set<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using tmii = map<int, int>;
using tmll = map<ll, ll>;
using mii = unordered_map<int, int>;
using mll = unordered_map<ll, ll>;
using pqi = priority_queue<int>;
using pqig = priority_queue<int, vi, greater<int>>;
using pql = priority_queue<ll>;
using pqlg = priority_queue<ll, vl, greater<ll>>;
using pqpii = priority_queue<pii>;
using pqpll = priority_queue<pll>;

#define tp3(T) tuple<T,T,T>
#define tp4(T) tuple<T,T,T,T>

#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sort_and_unique(a) sort(all(a));(a).resize(unique(all(a))-(a).begin())
#define outrange(x,min,max) ((x)<(min) || (x)>(max))

ll _start_time;
#define nano (chrono::system_clock::now().time_since_epoch().count())
#define reset_timer _start_time=nano
#define chime cout<<((nano-_start_time)/1e9)<<endl
#define init_rng mt19937_64 rng(nano ^ 19980731)
#define randint(a,b) ((a)+rng()%((b)-(a)+1))

#ifndef ONLINE_JUDGE
#define debug(x) (cout<<(#x)<<':'<<(x)<<'\n')
#else
#define debug(x)
#endif

void yesno(bool a) {
	cout << (a ? "Yes\n" : "No\n");
}

template<typename L, typename R>
ostream& operator<<(ostream& out, const pair<L, R>& p) {
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}

template<typename T1, typename T2, typename T3>
ostream& operator<<(ostream& out, const tuple<T1, T2, T3>& tp) {
	auto &[t1, t2, t3] = tp;
	out << '(' << t1 << ',' << t2 << ',' << t3 << ')';
	return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
	for (auto &i : v) out << i << ' ';
	out << nl;
	return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& v) {
	for (auto &i : v) out << i << ' ';
	out << nl;
	return out;
}

template<typename T>
ostream& operator<<(ostream& out, const unordered_set<T>& v) {
	for (auto &i : v) out << i << ' ';
	out << nl;
	return out;
}

template<typename K, typename V>
ostream& operator<<(ostream& out, const map<K, V>& m) {
	out << '[';
	for (auto &[k, v] : m) {
		out << k << ':' << v << sp;
	}
	out << "]\n";
	return out;
}

template<typename K, typename V>
ostream& operator<<(ostream& out, const unordered_map<K, V>& m) {
	out << '[';
	for (auto &[k, v] : m) {
		out << k << ':' << v << sp;
	}
	out << "]\n";
	return out;
}

void set_min(auto& x1,auto x2){
	x1=min(x1,x2);
}

void set_max(auto& x1,auto x2){
	x1=max(x1,x2);
}

bool check_palin(ll n,int t){
	vi v;
	while(n){
		v.push_back(n%t);
		n/=t;
	}
	int siz=v.size();
	for(int i=0,j=siz-1;i<j;i++,j--){
		if(v[i]!=v[j]) return false;
	}
	return true;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int k;
	ll n;
	cin>>k>>n;
	ll ans=0;
//	for(int i=1;i<=9;i++){
//		if(i<=n) ans+=i;
//	}
	for(int i=1;i<=999999;i++){
		ll x=i;
		ll y=i;
		while(y>0){
			x=x*10+y%10;
			y/=10;
		}
		if(x<=n && check_palin(x,k)) ans+=x;
	}
	for(int i=1;i<=999999;i++){
		ll x=i;
		ll y=i;
		bool flag=false;
		while(y>0){
			if(flag) x=x*10+y%10;
			else flag=true;
			y/=10;
		}
		if(x<=n && check_palin(x,k)) ans+=x;
	}
	cout<<ans;
}

Submission Info

Submission Time
Task C - Palindromic in Both Bases
User YocyCraft
Language C++ 20 (gcc 12.2)
Score 350
Code Size 3680 Byte
Status AC
Exec Time 429 ms
Memory 3628 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 3
AC × 33
Set Name Test Cases
Sample 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt
All 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 15 ms 3432 KiB
00-sample-02.txt AC 193 ms 3620 KiB
00-sample-03.txt AC 221 ms 3492 KiB
01-01.txt AC 15 ms 3492 KiB
01-02.txt AC 15 ms 3320 KiB
01-03.txt AC 429 ms 3432 KiB
01-04.txt AC 268 ms 3488 KiB
01-05.txt AC 192 ms 3620 KiB
01-06.txt AC 237 ms 3392 KiB
01-07.txt AC 206 ms 3488 KiB
01-08.txt AC 198 ms 3488 KiB
01-09.txt AC 327 ms 3468 KiB
01-10.txt AC 221 ms 3628 KiB
01-11.txt AC 15 ms 3432 KiB
01-12.txt AC 25 ms 3432 KiB
01-13.txt AC 15 ms 3616 KiB
01-14.txt AC 25 ms 3488 KiB
01-15.txt AC 15 ms 3428 KiB
01-16.txt AC 15 ms 3564 KiB
01-17.txt AC 15 ms 3488 KiB
01-18.txt AC 15 ms 3420 KiB
01-19.txt AC 310 ms 3492 KiB
01-20.txt AC 15 ms 3368 KiB
01-21.txt AC 15 ms 3456 KiB
01-22.txt AC 15 ms 3556 KiB
01-23.txt AC 15 ms 3620 KiB
01-24.txt AC 15 ms 3436 KiB
01-25.txt AC 15 ms 3576 KiB
01-26.txt AC 15 ms 3496 KiB
01-27.txt AC 24 ms 3560 KiB
01-28.txt AC 15 ms 3488 KiB
01-29.txt AC 15 ms 3568 KiB
01-30.txt AC 15 ms 3620 KiB