結果
問題 | No.238 Mr. K's Another Gift |
ユーザー |
|
提出日時 | 2017-03-21 01:28:59 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,133 bytes |
コンパイル時間 | 1,623 ms |
コンパイル使用メモリ | 168,148 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 04:45:33 |
合計ジャッジ時間 | 4,070 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <bits/stdc++.h> using namespace std; bool isKaibun(string s) { int n = s.length(); for (int i = 0; i < n / 2; i++) { if (s[i] != s[n - 1 - i]) return false; } return true; } int main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; int n = s.length(); string c; if (isKaibun(s)) { c = s[n / 2]; s.insert(n / 2, c); cout << s << endl; return 0; } int cnt = 0, idx = -1; for (int i = 0; i < (n - 1) / 2; i++) { cnt += (s[i] != s[n - 1 - i - cnt]); if (cnt > 1) break; if (cnt == 1 && idx == -1) { idx = i; c = s[n - 1 - i]; i--; } } if (cnt == 0) { idx = (n - 1) / 2; c = s[n / 2]; } if (cnt <= 1) { s.insert(idx, c); cout << s << endl; return 0; } cnt = 0; idx = -1; reverse(s.begin(), s.end()); for (int i = 0; i < (n - 1) / 2; i++) { cnt += (s[i] != s[n - 1 - i - cnt]); if (cnt > 1) break; if (cnt == 1 && idx == -1) { idx = i; c = s[n - 1 - i]; i--; } } if (cnt == 0) { idx = (n - 1) / 2; c = s[n / 2]; } if (cnt <= 1) { s.insert(idx, c); cout << s << endl; return 0; } cout << "NA" << endl; return 0; }