結果

問題 No.238 Mr. K's Another Gift
ユーザー motimoti
提出日時 2015-07-22 16:07:01
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,008 bytes
コンパイル時間 599 ms
コンパイル使用メモリ 79,348 KB
実行使用メモリ 813,164 KB
最終ジャッジ日時 2023-09-22 21:13:02
合計ジャッジ時間 3,037 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 MLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

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