Submission #67542608


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
long long x,y,da=0;
long long ans=0;
queue<long long>q;
queue<long long>wk;
long long y_to_ten(long long q){
	long long c=0,mqc=0;
	while(1){
		long long b=q%10;
		c+=(pow(x,mqc)*b);
		if(q<10) break;
		q/=10;
		mqc++;
	}
	return c;
}
bool check(long long q){
	int g[15];
	int s=0;
	long long k=q;
	while(1){
		g[++s]=k%10;
		if(k<10) break;
		k/=10;
	}
	for(int i=1,j=s;i<=s;i++,j--){
		if(g[i]!=g[j]) return false;
	}
	return true;
}
int main(){
	cin>>x>>y;
	for(int i=1;i<x;i++){
		wk.push(1);
		q.push(i);
		wk.push(2);
		q.push(i*10+i);
	} 
	while(!q.empty()){
		long long mq=q.front();
		long long wc=wk.front();
		wk.pop();
		q.pop();
		if(y_to_ten(mq)>y) continue;
		if(check(y_to_ten(mq))==true){
			ans+=y_to_ten(mq);
		}
		for(int i=1;i<x;i++){
			q.push((mq*10)+i+(i*pow(10,wc+1)));
			wk.push(wc+2);
		}
		if(mq%10==1){
			mq-=(mq%10);
		    mq-=(((long long)(mq/pow(10,wc-1))%10)*pow(10,wc-1));
	    	for(int i=1;i<x;i++){
	    		q.push((mq*10)+i+(i*pow(10,wc+1)));
	    		wk.push(wc+2);
	    	}
	    }
	
	}

	cout<<ans;
	return 0;
}

Submission Info

Submission Time
Task C - Palindromic in Both Bases
User Fireflies
Language C++ 20 (gcc 12.2)
Score 0
Code Size 1160 Byte
Status TLE
Exec Time 3367 ms
Memory 895432 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 350
Status
AC × 1
TLE × 2
AC × 20
TLE × 13
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 1 ms 3644 KiB
00-sample-02.txt TLE 3331 ms 293148 KiB
00-sample-03.txt TLE 3324 ms 190024 KiB
01-01.txt AC 1 ms 3644 KiB
01-02.txt AC 1 ms 3756 KiB
01-03.txt TLE 3310 ms 3496 KiB
01-04.txt TLE 3367 ms 895432 KiB
01-05.txt TLE 3331 ms 293236 KiB
01-06.txt TLE 3317 ms 117496 KiB
01-07.txt TLE 3322 ms 166092 KiB
01-08.txt TLE 3329 ms 258604 KiB
01-09.txt TLE 3361 ms 777524 KiB
01-10.txt TLE 3325 ms 190036 KiB
01-11.txt AC 1 ms 3768 KiB
01-12.txt AC 204 ms 11260 KiB
01-13.txt AC 1 ms 3628 KiB
01-14.txt AC 202 ms 11216 KiB
01-15.txt AC 1 ms 3668 KiB
01-16.txt AC 9 ms 4044 KiB
01-17.txt AC 1 ms 3616 KiB
01-18.txt AC 9 ms 3896 KiB
01-19.txt TLE 3360 ms 770784 KiB
01-20.txt AC 1 ms 3704 KiB
01-21.txt AC 8 ms 4044 KiB
01-22.txt AC 1 ms 3656 KiB
01-23.txt AC 2 ms 3584 KiB
01-24.txt AC 2 ms 3740 KiB
01-25.txt TLE 3313 ms 3440 KiB
01-26.txt TLE 3310 ms 3456 KiB
01-27.txt AC 112 ms 7040 KiB
01-28.txt AC 1 ms 3504 KiB
01-29.txt AC 1 ms 3692 KiB
01-30.txt AC 1 ms 3572 KiB