結果
| 問題 |
No.238 Mr. K's Another Gift
|
| コンテスト | |
| ユーザー |
よっか
|
| 提出日時 | 2015-07-05 23:45:47 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,232 bytes |
| コンパイル時間 | 640 ms |
| コンパイル使用メモリ | 88,028 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-07-08 00:59:32 |
| 合計ジャッジ時間 | 4,328 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 4 TLE * 1 -- * 35 |
ソースコード
#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;
}
よっか