結果

問題 No.238 Mr. K's Another Gift
ユーザー moti
提出日時 2015-07-22 16:07:01
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,008 bytes
コンパイル時間 835 ms
コンパイル使用メモリ 84,008 KB
実行使用メモリ 815,104 KB
最終ジャッジ日時 2024-07-08 11:48:16
合計ジャッジ時間 5,722 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 3 WA * 2 MLE * 1 -- * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int N;
string s;
string ans;

void dfs(int a, int b, bool used, string const& str) {

  if( (N+used) % 2 == 0 && a - 1 == b ) {
    string t = str; reverse(t.begin(), t.end());
    string u = !used ? "x" : "";
    ans = str + u + t;
    return;
  }
  if( (N+used) % 2 == 1 && a - 2 == b ) {
    string t = str; reverse(t.begin(), t.end());
    string u = !used ? "x" : "";
    ans = str + u + t.substr(1);
    return;
  }

  if(s[a] == s[b]) {
    dfs(a+1, b-1, used, str + s[a]);
  }
  else if(!used) {
    dfs(a+1, b, true, str + s[a]);
    dfs(a, b-1, true, str + s[b]);
  }

}

int main() {

  cin >> s;
  N = s.size();
  dfs(0, N-1, false, "");
  if(ans.empty()) {
    cout << "NA\n";
  }
  else {
    cout << ans << endl;
  }

  return 0;
}
0