結果

問題 No.2234 palindromer
ユーザー vjudge1
提出日時 2025-03-22 21:25:28
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 912 bytes
コンパイル時間 1,654 ms
コンパイル使用メモリ 161,944 KB
実行使用メモリ 7,324 KB
最終ジャッジ日時 2025-03-22 21:25:31
合計ジャッジ時間 2,754 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 6 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define int long long

#define double long double

#define INF (int)(1e18)

#define maxn 1100005

using namespace std;

string s,t;

string ss;

int h[maxn];

signed main() {
	
	ios::sync_with_stdio(0);
	
	cin.tie(0);
	
	cout.tie(0);
	
	cin >> s;
	
	for(auto i : s){
		
		t += '@';
		
		t += i;
		
	}
	
	t += '@';
	
	ss = s;
	
	s = t;
	
	int n = s.length();
	
	int N = ss.length();
	
	for(int i = 0,j = 0;i < n;++ i){
		
		if(i <= j + h[j]){
			
			h[i] = min(h[2 * j - i],j + h[j] - i);
			
		}
		
		while(i - h[i] >= 0 && i + h[i] < n && s[i - h[i]] == s[i + h[i]]) ++ h[i];
		
		if(i + h[i] > j + h[j]) j = i;
		
	}
	
	int ans = INF;
	
	for(int i = n - 1;i > 0;i --){
		
		if(h[i] == n - i){
			
			int cnt = h[i] / 2 * 2;
			
			ans = min(ans,N - cnt);
			
		}
		
	}
	
//	cout << ans << "\n";
	
	cout << ss;
	
	for(int i = ans - 1;i >= 0;-- i) cout << ss[i];
	
	return 0;
	
}
/*

*/
0