Submission #55788066
Source Code Expand
#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;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Palindromic Number |
| User | Ashishgup |
| Language | C++ 20 (gcc 12.2) |
| Score | 350 |
| Code Size | 1011 Byte |
| Status | AC |
| Exec Time | 1 ms |
| Memory | 3596 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 350 / 350 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| 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 |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 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 |