Submission #67558044


Source Code Expand

#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <queue>

using namespace std;

long long intrev(long long x)
{
    long long ret = 0;
    while(x > 0)
    {
        ret = ret*10 + x%10;
        x /= 10;
    }
    return ret;
}

bool check(long long x, int basis)
{
    string c = "";
    while(x > 0)
    {
        long long rem = x%basis;
        x /= basis;
        c += rem + '0';
    }
    string cop = c;
    reverse(cop.begin(), cop.end());
    if(c == cop)
        return true;
    return false;
}

int main()
{
    long long n, dex[10] = {0,1,10,100,1000,10000,100000, 1000000, 10000000, 100000000}, ans = 0;
    int a;
    scanf("%d %lld", &a, &n);

    for(int i = 1 ; i <= 9 ; i++)
    {
        if(check(i,a) && i <= n)
            ans += i;
    }

    for(long long i = 1 ; i <= n ; i++)
    {
        int inval = log10(i) + 1;
        long long reversed = intrev((long long)i);
        long long constructed = i*dex[inval + 1] + reversed;
        if(constructed > n)
            break;
        if(check(constructed,a))
            ans += constructed;
        for(int mid = 0 ; mid <= 9 ; mid++)
        {
            constructed = (i*10 + mid)*dex[inval + 1] + reversed;
            if(check(constructed,a) && constructed <= n)
                ans += constructed;
        }
    }
    printf("%lld\n", ans);
    return 0;
}
//6000000 -> 564500732
//999999  -> 863353515

Submission Info

Submission Time
Task C - Palindromic in Both Bases
User MichaelH
Language C++ 17 (gcc 12.2)
Score 350
Code Size 1508 Byte
Status AC
Exec Time 2615 ms
Memory 4088 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:41:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |     scanf("%d %lld", &a, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~

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 4084 KiB
00-sample-02.txt AC 734 ms 3868 KiB
00-sample-03.txt AC 1159 ms 4068 KiB
01-01.txt AC 1 ms 4024 KiB
01-02.txt AC 1 ms 3692 KiB
01-03.txt AC 2615 ms 3864 KiB
01-04.txt AC 1373 ms 3864 KiB
01-05.txt AC 729 ms 3868 KiB
01-06.txt AC 1262 ms 4020 KiB
01-07.txt AC 981 ms 3872 KiB
01-08.txt AC 691 ms 3944 KiB
01-09.txt AC 1705 ms 3944 KiB
01-10.txt AC 1158 ms 3924 KiB
01-11.txt AC 1 ms 3988 KiB
01-12.txt AC 12 ms 4088 KiB
01-13.txt AC 1 ms 3988 KiB
01-14.txt AC 11 ms 3868 KiB
01-15.txt AC 1 ms 4028 KiB
01-16.txt AC 1 ms 4016 KiB
01-17.txt AC 1 ms 4008 KiB
01-18.txt AC 1 ms 3932 KiB
01-19.txt AC 1533 ms 4088 KiB
01-20.txt AC 1 ms 4044 KiB
01-21.txt AC 1 ms 3868 KiB
01-22.txt AC 1 ms 3796 KiB
01-23.txt AC 1 ms 3936 KiB
01-24.txt AC 1 ms 4020 KiB
01-25.txt AC 2 ms 4068 KiB
01-26.txt AC 2 ms 4088 KiB
01-27.txt AC 8 ms 4016 KiB
01-28.txt AC 1 ms 3872 KiB
01-29.txt AC 1 ms 3892 KiB
01-30.txt AC 1 ms 3952 KiB