結果
問題 |
No.238 Mr. K's Another Gift
|
ユーザー |
|
提出日時 | 2015-08-06 22:40:26 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 1,187 bytes |
コンパイル時間 | 1,532 ms |
コンパイル使用メモリ | 161,924 KB |
実行使用メモリ | 7,252 KB |
最終ジャッジ日時 | 2024-07-18 03:47:08 |
合計ジャッジ時間 | 3,178 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <bits/stdc++.h> #define rep(i, a) for (int i = 0; i < (a); i++) #define rep2(i, a, b) for (int i = (a); i < (b); i++) #define repr(i, a) for (int i = (a) - 1; i >= 0; i--) #define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--) using namespace std; typedef long long ll; const ll inf = 1e9; const ll mod = 1e9 + 7; typedef unsigned long long ull; const ull B = 1e8 + 7; // abcde // 12345 // edcbxa ull sh[200000], th[200000]; ull pb[200000]; string solve(string s) { string t = s; reverse(t.begin(), t.end()); int l = s.length(); pb[0] = 1; rep (i, l) { pb[i + 1] = pb[i] * B; } rep (i, l) { sh[i + 1] = sh[i] + s[i] * pb[i]; th[i + 1] = th[i] + t[i] * pb[i]; } rep (i, l + 1) { rep (j, 26) { char ch = 'a' + j; ull ssh = sh[i] + ch * pb[i] + (sh[l] - sh[i]) * B; int k = l - i; ull tth = th[k] + ch * pb[k] + (th[l] - th[k]) * B; if (ssh == tth) { s.insert(i, 1, ch); return s; } } } return "NA"; } int main() { string s; cin >> s; cout << solve(s) << endl; }