結果
問題 |
No.238 Mr. K's Another Gift
|
ユーザー |
|
提出日時 | 2020-09-04 17:50:42 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,260 bytes |
コンパイル時間 | 811 ms |
コンパイル使用メモリ | 75,268 KB |
最終ジャッジ日時 | 2025-01-14 04:38:59 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 WA * 2 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <string> void solve() { std::string s; std::cin >> s; int n = s.length(); std::string fore, back; auto dfs = [&](auto&& f, int l, int r, bool rem) -> bool { if (l == r) fore.push_back(s[l++]); if (l > r) { if (rem) back.push_back('a'); return true; } if (s[l] == s[r]) { if (f(f, l + 1, r - 1, rem)) { fore.push_back(s[l]); back.push_back(s[r]); return true; } } if (rem) { if (f(f, l, r - 1, false)) { fore.push_back(s[r]); back.push_back(s[r]); return true; } if (f(f, l + 1, r, false)) { fore.push_back(s[l]); back.push_back(s[l]); return true; } } return false; }; if (!dfs(dfs, 0, n - 1, true)) { std::cout << "NA\n"; } else { std::reverse(fore.begin(), fore.end()); std::cout << fore << back << "\n"; } } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }