提出 #67533680
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
long long isPalindrome(const string& val, long long lim, int B) {
long long n = stoll(val);
if (n > lim) {
return 0;
}
string res = "";
while (n) {
res.push_back('0' + (n%B));
n /= B;
}
for (int k = 0; k < (int) res.size(); k++) {
if (res[k] != res[res.size() - 1 - k]) {
return 0;
}
}
return stoll(val);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long A, N;
cin >> A >> N;
long long cnt = 0;
for (int d = 1; d <= 9; d++) {
cnt += isPalindrome(to_string(d), N, A);
}
for (int i = 1; i <= 1000000; i++) {
string num = to_string(i);
string rev = num;
reverse(rev.begin(), rev.end());
cnt += isPalindrome(num + rev, N, A);
for (int d = 0; d <= 9; d++) {
string dig(1, '0' + d);
cnt += isPalindrome(num + dig + rev, N, A);
}
}
cout << cnt << "\n";
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - Palindromic in Both Bases |
| ユーザ | AQT |
| 言語 | C++ 20 (gcc 12.2) |
| 得点 | 350 |
| コード長 | 1059 Byte |
| 結果 | AC |
| 実行時間 | 849 ms |
| メモリ | 3696 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 350 / 350 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| 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 | 499 ms | 3460 KiB |
| 00-sample-02.txt | AC | 598 ms | 3356 KiB |
| 00-sample-03.txt | AC | 627 ms | 3504 KiB |
| 01-01.txt | AC | 496 ms | 3596 KiB |
| 01-02.txt | AC | 495 ms | 3588 KiB |
| 01-03.txt | AC | 849 ms | 3576 KiB |
| 01-04.txt | AC | 668 ms | 3408 KiB |
| 01-05.txt | AC | 600 ms | 3692 KiB |
| 01-06.txt | AC | 643 ms | 3572 KiB |
| 01-07.txt | AC | 610 ms | 3452 KiB |
| 01-08.txt | AC | 595 ms | 3576 KiB |
| 01-09.txt | AC | 731 ms | 3448 KiB |
| 01-10.txt | AC | 634 ms | 3444 KiB |
| 01-11.txt | AC | 498 ms | 3560 KiB |
| 01-12.txt | AC | 502 ms | 3508 KiB |
| 01-13.txt | AC | 499 ms | 3508 KiB |
| 01-14.txt | AC | 501 ms | 3644 KiB |
| 01-15.txt | AC | 497 ms | 3592 KiB |
| 01-16.txt | AC | 498 ms | 3448 KiB |
| 01-17.txt | AC | 495 ms | 3576 KiB |
| 01-18.txt | AC | 495 ms | 3512 KiB |
| 01-19.txt | AC | 718 ms | 3644 KiB |
| 01-20.txt | AC | 498 ms | 3580 KiB |
| 01-21.txt | AC | 496 ms | 3696 KiB |
| 01-22.txt | AC | 500 ms | 3404 KiB |
| 01-23.txt | AC | 496 ms | 3512 KiB |
| 01-24.txt | AC | 496 ms | 3512 KiB |
| 01-25.txt | AC | 497 ms | 3584 KiB |
| 01-26.txt | AC | 497 ms | 3576 KiB |
| 01-27.txt | AC | 504 ms | 3584 KiB |
| 01-28.txt | AC | 497 ms | 3404 KiB |
| 01-29.txt | AC | 494 ms | 3580 KiB |
| 01-30.txt | AC | 496 ms | 3500 KiB |