結果
問題 | No.491 10^9+1と回文 |
ユーザー |
👑 |
提出日時 | 2024-06-09 14:28:32 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 79 ms / 1,000 ms |
コード長 | 1,382 bytes |
コンパイル時間 | 1,513 ms |
コンパイル使用メモリ | 96,620 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-30 05:22:26 |
合計ジャッジ時間 | 4,815 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 103 |
ソースコード
#include <iostream>#include <string>#include <algorithm>int main() {std::string n;std::cin >> n;while (n.length() < 18) {n = "0" + n;}if (n.length() == 19) {n = std::string(18, '9');}std::string S = n.substr(0, 9);std::string T = n.substr(9, 9);long long S_num = std::stoll(S);long long T_num = std::stoll(T);long long num;if (T_num >= S_num) {num = S_num;} else {num = S_num - 1;}long long ans = std::min(num, 9LL);long long x = 1;while (true) {bool br = false;for (long long i = x; i < 10 * x; ++i) {std::string i_str = std::to_string(i);std::string z = i_str + std::string(i_str.rbegin(), i_str.rend());if (std::stoll(z) <= num) {ans += 1;} else {br = true;}for (int j = 0; j < 10; ++j) {std::string z_with_j = i_str + std::to_string(j) + std::string(i_str.rbegin(), i_str.rend());if (std::stoll(z_with_j) <= num) {ans += 1;} else {br = true;}}}x *= 10;if (br) {break;}}std::cout << ans << std::endl;return 0;}