結果

問題 No.238 Mr. K's Another Gift
ユーザー vain0vain0
提出日時 2015-07-05 23:02:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,439 bytes
コンパイル時間 1,525 ms
コンパイル使用メモリ 73,544 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 07:06:48
合計ジャッジ時間 3,020 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>
#include <functional>
#include <set>
#include <ctime>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#ifndef ONLINE_JUDGE //POJ
# include <complex>
# include <random>
# include <array>
# define mkt make_tuple
# define empb emplace_back
#endif
#ifdef _LOCAL
# include "for_local.h"
#endif
using namespace std;
typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull;
#define repi(_I, _B, _E) for(int _I = (_B); (_I) < (_E); ++ (_I))
#define rep(_I, _N) for(int _I = 0; (_I) < (_N); ++ (_I))
#define mkp make_pair
#define all(_X) (_X).begin(), (_X).end()


string src;

bool palindromize(int i, int ri, bool canInsert, int& pos, char& ch)
{
	while ( i <= ri ) {
		if ( src[i] != src[ri] ) {
			if ( canInsert ) {
				if ( palindromize(i, ri - 1, false, pos, ch) ) { pos = i; ch = src[ri]; return true; }
				if ( palindromize(i + 1, ri, false, pos, ch) ) { pos = ri + 1; ch = src[i]; return true; }
			}
			return false;
		}
		++i;
		--ri;
	}

	if ( canInsert ) {
		int mid = i + (ri - i) / 2;
		pos = mid; ch = src[mid];
	}
	return true;
}

signed main()
{
	cin >> src;

	int pos = 0;
	char ch = src[0];

	if ( palindromize(0, src.size() - 1, true, pos, ch) ) {
		src.insert(pos, 1, ch);
		cout << src << endl;
	} else {
		cout << "NA" << endl;
	}
	return 0;
}
0