結果

問題 No.238 Mr. K's Another Gift
ユーザー よっかよっか
提出日時 2015-07-05 23:45:47
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,232 bytes
コンパイル時間 835 ms
コンパイル使用メモリ 87,592 KB
実行使用メモリ 11,476 KB
最終ジャッジ日時 2023-09-22 08:46:13
合計ジャッジ時間 4,360 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
11,476 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 92 ms
4,384 KB
testcase_04 TLE -
testcase_05 -- -
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 <vector>
#include <deque>
#include <stack>
#include <memory>
#include <functional>
#include <algorithm>
#include <map>
#include <list>
#include <complex>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <array>
using namespace std;
typedef std::pair<int, int> pii;
typedef long long int ll;

#define pb push_back

const long long int MOD = 1e9+7;

int longest_palindrome(char *text, int n) {
  int rad[2*n], i, j, k;
  for (i = 0, j = 0; i < 2*n; i += k, j = max(j-k, 0)) {
    while (i-j >= 0 && i+j+1 < 2*n && text[(i-j)/2] == text[(i+j+1)/2]) ++j;
    rad[i] = j;
    for (k = 1; i-k >= 0 && rad[i]-k >= 0 && rad[i-k] != rad[i]-k; ++k)
      rad[i+k] = min(rad[i-k], rad[i]-k);
  }
  return *max_element(rad, rad+2*n); // ret. centre of the longest palindrome
}

int main(){
	
	string s;
	cin >> s;

	for (int i = 0; i < s.size()+1; ++i) {
		for (char j = 'a'; j <= 'z'; ++j) {
			string tmp = s;
			string r;
			r.append(1,j);

			tmp.insert(i, r);
			if(longest_palindrome((char*)tmp.c_str(), tmp.size()) == tmp.size()){
				std::cout << tmp << std::endl;
				return 0;
			}
		}
	}

	std::cout << "NA" << std::endl;
	return 0;
}
0