結果
問題 | No.491 10^9+1と回文 |
ユーザー | 🍮かんプリン |
提出日時 | 2020-06-05 00:39:01 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 6 ms / 1,000 ms |
コード長 | 1,013 bytes |
コンパイル時間 | 1,300 ms |
コンパイル使用メモリ | 160,224 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-30 21:40:45 |
合計ジャッジ時間 | 4,139 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 103 |
ソースコード
/** * @FileName a.cpp * @Author kanpurin * @Created 2020.06.05 00:38:56 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; string next_str(string s) { int l = 0, r = s.size() - 1; while (r - l > 1) { l++; r--; } if (s[l] != '9') { s[l]++; if (l != r) { s[r]++; } return s; } while (s[l] == '9') { s[l] = '0'; s[r] = '0'; l--; r++; } if (l == -1) { s[0] = '1'; s.push_back('1'); return s; } s[l]++; s[r]++; return s; } int to_num(string s){ int res = 0; for (int i = 0; i < s.size(); i++) { res*=10; res += s[i]-'0'; } return res; } int main() { ll n; cin >> n; const int mod = 1e9 + 1; ll m = n / mod; string t = "1"; int ans = 0; while(to_num(t) <= m) { ans++; t = next_str(t); } cout << ans << endl; return 0; }