Submission #67546369


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool shi(ll b) {
    if (b < 0) return false;
    ll c = 0, d = b;
    while (b > 0) {
        c = c * 10 + b % 10;
        b /= 10;
    }
    return c == d;
}
bool c(ll x, ll base) {
    if (x == 0) return true;
    vector<int> digits;
    ll t = x;
    while (t > 0) {
        digits.push_back(t % base);
        t /= base;
    }
    int l = 0, r = digits.size() - 1;
    while (l < r) {
        if (digits[l] != digits[r]) 
            return false;
        l++;
        r--;
    }
    return true;
}
int main() {
    ll a, n, e = 0;
    cin >> a >> n;
    int len = to_string(n).size();
    for (int d = 1; d <= len; d++) {
        int half = (d + 1) / 2;
        ll start = pow(10, half - 1);
        ll end = pow(10, half) - 1;
        for (ll j = start; j <= end; j++) {
            ll pal = j;
            ll temp = (d % 2 == 1) ? j / 10 : j;
            ll x = temp;
            while (x > 0) {
                pal = pal * 10 + (x % 10);
                x /= 10;
            }
            if (pal > n) break;
            if (shi(pal) && c(pal, a)) {
                e += pal;
            }
        }
    }
    cout << e;
    return 0;
}

Submission Info

Submission Time
Task C - Palindromic in Both Bases
User a_little_cat
Language C++ 20 (gcc 12.2)
Score 350
Code Size 1266 Byte
Status AC
Exec Time 459 ms
Memory 3824 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 1 ms 3612 KiB
00-sample-02.txt AC 226 ms 3616 KiB
00-sample-03.txt AC 250 ms 3664 KiB
01-01.txt AC 1 ms 3680 KiB
01-02.txt AC 1 ms 3588 KiB
01-03.txt AC 459 ms 3688 KiB
01-04.txt AC 296 ms 3620 KiB
01-05.txt AC 226 ms 3664 KiB
01-06.txt AC 265 ms 3824 KiB
01-07.txt AC 240 ms 3752 KiB
01-08.txt AC 231 ms 3704 KiB
01-09.txt AC 353 ms 3712 KiB
01-10.txt AC 250 ms 3748 KiB
01-11.txt AC 1 ms 3556 KiB
01-12.txt AC 13 ms 3716 KiB
01-13.txt AC 1 ms 3756 KiB
01-14.txt AC 13 ms 3680 KiB
01-15.txt AC 1 ms 3816 KiB
01-16.txt AC 2 ms 3680 KiB
01-17.txt AC 1 ms 3812 KiB
01-18.txt AC 2 ms 3652 KiB
01-19.txt AC 334 ms 3620 KiB
01-20.txt AC 1 ms 3680 KiB
01-21.txt AC 1 ms 3744 KiB
01-22.txt AC 1 ms 3664 KiB
01-23.txt AC 1 ms 3652 KiB
01-24.txt AC 1 ms 3660 KiB
01-25.txt AC 1 ms 3764 KiB
01-26.txt AC 2 ms 3664 KiB
01-27.txt AC 11 ms 3684 KiB
01-28.txt AC 1 ms 3820 KiB
01-29.txt AC 1 ms 3752 KiB
01-30.txt AC 1 ms 3608 KiB