結果
問題 | No.238 Mr. K's Another Gift |
ユーザー |
![]() |
提出日時 | 2015-07-05 23:07:11 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 928 bytes |
コンパイル時間 | 1,114 ms |
コンパイル使用メモリ | 160,876 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-07 23:45:26 |
合計ジャッジ時間 | 2,549 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <bits/stdc++.h> #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,b) FOR(i,0,b) #define F first #define S second #define PB push_back #define BE(c) c.begin(),c.end() using namespace std; typedef long long LL; typedef LL ut; typedef vector<ut> VI; const ut INF=1<<30; const int SIZE=1e+6; const ut eps=1e-9; VI primes; string answer; bool solve(string str,int s,int e,bool used){ while(s<=e){ if(str[s]==str[e]){ s++; e--; } else{ if(used) return false; if(solve(str,s+1,e,true)){ str.insert(e+1,string(1,str[s])); s++; } else if(solve(str,s,e-1,true)){ str.insert(s,string(1,str[e])); s++; } else return false; used=true; } } if(!used){ str.insert((s+e)/2,string(1,str[(s+e)/2])); } answer=str; return true; } int main(){ string s; cin >> s; int N=s.size(); if(solve(s,0,N-1,false)) cout << answer<<endl; else cout << "NA" << endl; return 0; }