提出 #55788066
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define endl "\n"
const int N = 105;
int n;
int getNumPalindromes(int digits) {
if(digits == 1)
return 10;
int modifiable = (digits + 1) / 2;
int firstDigit = 9; // 1 to 9
int otherDigits = 1;
for(int i = 1; i <= modifiable - 1; i++) {
otherDigits *= 10; // 0 to 9
}
return firstDigit * otherDigits;
}
void nthPalindromeOfKdigits(int k) { // 2: 1, 3: 10, 4:10
if(k == 1) {
cout << n - 1;
return;
}
int firstHalf = (k - 1) / 2;
int value = 1;
for(int i = 1; i <= firstHalf; i++) {
value *= 10;
}
value += (n - 1);
cout << value;
if(k % 2)
value /= 10;
while(value) {
cout << value % 10;
value /= 10;
}
}
int32_t main() {
IOS;
cin >> n;
int k = 1; // Number of digits
while(getNumPalindromes(k) < n) {
n -= getNumPalindromes(k);
k++;
}
nthPalindromeOfKdigits(k);
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - Palindromic Number |
| ユーザ | Ashishgup |
| 言語 | C++ 20 (gcc 12.2) |
| 得点 | 350 |
| コード長 | 1011 Byte |
| 結果 | AC |
| 実行時間 | 1 ms |
| メモリ | 3596 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 350 / 350 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_1_00.txt, 01_random_1_01.txt, 01_random_1_02.txt, 01_random_1_03.txt, 01_random_1_04.txt, 02_random_2_00.txt, 02_random_2_01.txt, 02_random_2_02.txt, 02_random_2_03.txt, 02_random_2_04.txt, 02_random_2_05.txt, 02_random_2_06.txt, 02_random_2_07.txt, 02_random_2_08.txt, 02_random_2_09.txt, 03_max_00.txt, 04_min_00.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3420 KiB |
| 00_sample_01.txt | AC | 1 ms | 3308 KiB |
| 00_sample_02.txt | AC | 1 ms | 3420 KiB |
| 01_random_1_00.txt | AC | 1 ms | 3520 KiB |
| 01_random_1_01.txt | AC | 1 ms | 3384 KiB |
| 01_random_1_02.txt | AC | 1 ms | 3460 KiB |
| 01_random_1_03.txt | AC | 1 ms | 3468 KiB |
| 01_random_1_04.txt | AC | 1 ms | 3464 KiB |
| 02_random_2_00.txt | AC | 1 ms | 3384 KiB |
| 02_random_2_01.txt | AC | 1 ms | 3392 KiB |
| 02_random_2_02.txt | AC | 1 ms | 3324 KiB |
| 02_random_2_03.txt | AC | 1 ms | 3460 KiB |
| 02_random_2_04.txt | AC | 1 ms | 3384 KiB |
| 02_random_2_05.txt | AC | 1 ms | 3520 KiB |
| 02_random_2_06.txt | AC | 1 ms | 3596 KiB |
| 02_random_2_07.txt | AC | 1 ms | 3412 KiB |
| 02_random_2_08.txt | AC | 1 ms | 3520 KiB |
| 02_random_2_09.txt | AC | 1 ms | 3464 KiB |
| 03_max_00.txt | AC | 1 ms | 3468 KiB |
| 04_min_00.txt | AC | 1 ms | 3320 KiB |