Submission #67537711
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long
#define PII pair<int,int>
#define mod 998244353
const int MOD=1e9+7;
const int N=1e5+10;
int read() {char act = 0;int f = 1, x= 0;while (act = getchar(), act < '0' && act != '-');if (act == '-') f = -1, act = getchar();x = act - '0';while (act = getchar(), act >= '0') x = x * 10 + act - '0';return x * f;}
int flip(int n) {
if (n == 0)
return 0;
int rev = 0;
while (n) {
rev = rev * 10 + n % 10;
n /= 10;
}
return rev;
}
bool check(int num, int A) {
if (num == 0) {
return true;
}
vector<int> digit;
int n = num;
while (n) {
digit.push_back(n % A);
n /= A;
}
int len = digit.size();
for (int i = 0; i < len/2; i++) {
if (digit[i] != digit[len-1-i]) {
return false;
}
}
return true;
}
void solve(){
int pow10[15];
pow10[0] = 1;
for (int i = 1; i < 15; i++) {
pow10[i] = pow10[i-1] * 10;
}
int A,N;
cin >> A >> N;
int sum = 0,d_max = 0,temp = N;
while (temp) {
d_max++;
temp /= 10;
}
for (int d = 1; d <= d_max; d++) {
int half_len = (d + 1) / 2;
int low = pow10[half_len - 1];
int high = pow10[half_len] - 1;
for (int x = low; x <= high; x++) {
int num;
if (d % 2 == 0) {
int rev = flip(x);
num = x * pow10[d / 2] + rev;
} else {
int y = x / 10;
int rev = flip(y);
num = x * pow10[half_len - 1] + rev;
}
if (num > N) {
break;
}
if (check(num, A)) {
sum += num;
}
}
}
cout << sum << endl;
}
signed main()
{
IOS;
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Palindromic in Both Bases |
| User | Freakkk |
| Language | C++ 20 (gcc 12.2) |
| Score | 350 |
| Code Size | 2135 Byte |
| Status | AC |
| Exec Time | 424 ms |
| Memory | 3604 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 350 / 350 | ||||
| Status |
|
|
| 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 | 3420 KiB |
| 00-sample-02.txt | AC | 189 ms | 3488 KiB |
| 00-sample-03.txt | AC | 214 ms | 3408 KiB |
| 01-01.txt | AC | 1 ms | 3600 KiB |
| 01-02.txt | AC | 2 ms | 3416 KiB |
| 01-03.txt | AC | 424 ms | 3468 KiB |
| 01-04.txt | AC | 261 ms | 3488 KiB |
| 01-05.txt | AC | 189 ms | 3476 KiB |
| 01-06.txt | AC | 231 ms | 3476 KiB |
| 01-07.txt | AC | 201 ms | 3424 KiB |
| 01-08.txt | AC | 204 ms | 3400 KiB |
| 01-09.txt | AC | 320 ms | 3476 KiB |
| 01-10.txt | AC | 214 ms | 3476 KiB |
| 01-11.txt | AC | 1 ms | 3336 KiB |
| 01-12.txt | AC | 11 ms | 3344 KiB |
| 01-13.txt | AC | 1 ms | 3468 KiB |
| 01-14.txt | AC | 11 ms | 3424 KiB |
| 01-15.txt | AC | 2 ms | 3604 KiB |
| 01-16.txt | AC | 2 ms | 3476 KiB |
| 01-17.txt | AC | 1 ms | 3424 KiB |
| 01-18.txt | AC | 2 ms | 3464 KiB |
| 01-19.txt | AC | 302 ms | 3544 KiB |
| 01-20.txt | AC | 1 ms | 3468 KiB |
| 01-21.txt | AC | 1 ms | 3464 KiB |
| 01-22.txt | AC | 1 ms | 3464 KiB |
| 01-23.txt | AC | 1 ms | 3464 KiB |
| 01-24.txt | AC | 1 ms | 3424 KiB |
| 01-25.txt | AC | 1 ms | 3484 KiB |
| 01-26.txt | AC | 2 ms | 3336 KiB |
| 01-27.txt | AC | 10 ms | 3420 KiB |
| 01-28.txt | AC | 1 ms | 3404 KiB |
| 01-29.txt | AC | 1 ms | 3600 KiB |
| 01-30.txt | AC | 1 ms | 3416 KiB |