Submission #67559564


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using int128 = __int128;
using State = string::const_iterator;
class ParseError {};
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define reps(i, l, r) for(ll i = (l); i < (r); i++)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl "\n";
const ll INF = LLONG_MAX / 4;
const ld inf = numeric_limits<long double>::max() / (ld)4;
const ll mod1 = 1000000007;
const ll mod2 = 998244353;
const ld pi = 3.1415926535897;
ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
ll dy[8] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T>
bool chmax(T &a, const T& b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
    if (a > b) { a = b; return true; }
    return false;
}
void solve() {
    ll A; cin >> A;
    ll N; cin >> N;
    unsigned long long ans = 0;
    reps(i, 1, 1000000) {
        string v = to_string(i);
        string rev = v; reverse(rev.begin(), rev.end());
        string S = v + rev;
        string T = v + rev.substr(1, T.size() - 1);
        ll s = stoll(S), t = stoll(T);
        bool check1 = (s <= N), check2 = (t <= N);
        string Sa, Ta;
        while (s != 0) {
            Sa.push_back(char('0' + (s % A)));
            s /= A;
        }
        while (t != 0) {
            Ta.push_back(char('0' + (t % A)));
            t /= A;
        }
        string revSa = Sa, revTa = Ta;
        reverse(revSa.begin(), revSa.end());
        reverse(revTa.begin(), revTa.end());
        if (check1 && Sa == revSa) {ans += stoll(S);}
        if (check2 && Ta == revTa) {ans += stoll(T);}
        // cout << s << endl;
    }
    cout << ans << endl;
}
int main() {
    ll T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
}

Submission Info

Submission Time
Task C - Palindromic in Both Bases
User Oxojo
Language C++ 23 (gcc 12.2)
Score 0
Code Size 1928 Byte
Status WA
Exec Time 650 ms
Memory 3720 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 350
Status
AC × 3
AC × 25
WA × 8
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 258 ms 3580 KiB
00-sample-02.txt AC 266 ms 3572 KiB
00-sample-03.txt AC 305 ms 3568 KiB
01-01.txt AC 646 ms 3532 KiB
01-02.txt AC 257 ms 3568 KiB
01-03.txt AC 650 ms 3532 KiB
01-04.txt WA 385 ms 3580 KiB
01-05.txt AC 264 ms 3536 KiB
01-06.txt AC 351 ms 3536 KiB
01-07.txt AC 277 ms 3532 KiB
01-08.txt WA 254 ms 3528 KiB
01-09.txt WA 456 ms 3512 KiB
01-10.txt AC 305 ms 3536 KiB
01-11.txt AC 257 ms 3532 KiB
01-12.txt AC 257 ms 3568 KiB
01-13.txt AC 257 ms 3512 KiB
01-14.txt AC 259 ms 3524 KiB
01-15.txt AC 298 ms 3528 KiB
01-16.txt AC 300 ms 3508 KiB
01-17.txt AC 298 ms 3532 KiB
01-18.txt AC 300 ms 3540 KiB
01-19.txt WA 455 ms 3532 KiB
01-20.txt WA 451 ms 3580 KiB
01-21.txt WA 247 ms 3600 KiB
01-22.txt AC 248 ms 3536 KiB
01-23.txt WA 381 ms 3528 KiB
01-24.txt WA 382 ms 3536 KiB
01-25.txt AC 645 ms 3516 KiB
01-26.txt AC 645 ms 3576 KiB
01-27.txt AC 347 ms 3720 KiB
01-28.txt AC 345 ms 3576 KiB
01-29.txt AC 267 ms 3452 KiB
01-30.txt AC 268 ms 3528 KiB