提出 #67550662


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
long long a,n;

string base(long long x, long long a)
{
    string s="";
    while (x>0)
    {
        s += char('0' + x%a);
        x = x/a;
    }
    return s;
}

long long dx(string x)
{
    int o = 1;
    for (int i=0,j=x.size()-1; i<j; i++, j--)
        if (x[i] != x[j])
        {
            o = 0;
        }
    return o;
}



int main()
{
    cin >>a >>n;
    long long tong = 0;
    for (int l=1; l<=1000000; l++)
    {
        if (l>n)
            break;
        string s = to_string(l);
        string so2 = string(1,s[s.size()-1]);
        string so1 = s+so2;
        s.pop_back();
        so2 = s+so2;
        reverse(s.begin(),s.end());
        so1 += s;
        so2 += s;
        long long x = stoll(so1);
        long long y = stoll(so2);
        if (x<=n and dx(base(x,a)))
            tong += x;
        if (y<=n and dx(base(y,a)) and x != y)
            tong += y;
    }
    cout <<tong;
    return 0;
}

提出情報

提出日時
問題 C - Palindromic in Both Bases
ユーザ learnerxxx
言語 C++ 17 (Clang 16.0.6)
得点 350
コード長 1022 Byte
結果 AC
実行時間 407 ms
メモリ 3744 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 350 / 350
結果
AC × 3
AC × 33
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
00-sample-01.txt AC 1 ms 3740 KiB
00-sample-02.txt AC 176 ms 3616 KiB
00-sample-03.txt AC 198 ms 3520 KiB
01-01.txt AC 1 ms 3548 KiB
01-02.txt AC 1 ms 3680 KiB
01-03.txt AC 407 ms 3612 KiB
01-04.txt AC 246 ms 3544 KiB
01-05.txt AC 176 ms 3532 KiB
01-06.txt AC 225 ms 3576 KiB
01-07.txt AC 181 ms 3544 KiB
01-08.txt AC 171 ms 3520 KiB
01-09.txt AC 276 ms 3572 KiB
01-10.txt AC 197 ms 3532 KiB
01-11.txt AC 1 ms 3576 KiB
01-12.txt AC 97 ms 3600 KiB
01-13.txt AC 1 ms 3708 KiB
01-14.txt AC 97 ms 3544 KiB
01-15.txt AC 1 ms 3744 KiB
01-16.txt AC 92 ms 3520 KiB
01-17.txt AC 1 ms 3612 KiB
01-18.txt AC 92 ms 3544 KiB
01-19.txt AC 267 ms 3516 KiB
01-20.txt AC 7 ms 3736 KiB
01-21.txt AC 92 ms 3488 KiB
01-22.txt AC 1 ms 3488 KiB
01-23.txt AC 53 ms 3596 KiB
01-24.txt AC 48 ms 3524 KiB
01-25.txt AC 93 ms 3508 KiB
01-26.txt AC 92 ms 3616 KiB
01-27.txt AC 97 ms 3460 KiB
01-28.txt AC 1 ms 3616 KiB
01-29.txt AC 1 ms 3616 KiB
01-30.txt AC 1 ms 3736 KiB