結果

問題 No.238 Mr. K's Another Gift
ユーザー vain0vain0
提出日時 2015-07-05 22:55:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,420 bytes
コンパイル時間 583 ms
コンパイル使用メモリ 74,192 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 06:57:25
合計ジャッジ時間 3,204 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 3 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 4 ms
4,380 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 4 ms
4,380 KB
testcase_38 AC 3 ms
4,376 KB
testcase_39 AC 4 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:57:20: warning: overflow in conversion from ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} to ‘int’ changes value from ‘18446744073709551615’ to ‘-1’ [-Woverflow]
  int pos = string::npos;
                    ^~~~

ソースコード

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, int cntInsert, int& pos, char& ch)
{
	while ( i <= ri ) {
		if ( src[i] != src[ri] ) {
			if ( cntInsert > 0 ) {
				if ( palindromize(i, ri - 1, cntInsert - 1, pos, ch) ) { pos = i; ch = src[ri]; return true; }
				if ( palindromize(i + 1, ri, cntInsert - 1, pos, ch) ) { pos = ri + 1; ch = src[i]; return true; }
			}
			return false;
		}
		++i;
		--ri;
	}
	if ( i > ri ) { pos = i; ch = 'a'; }
	return true;
}

signed main()
{
	cin >> src;

	int pos = string::npos;
	char ch = '\0';

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