結果
| 問題 |
No.2234 palindromer
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-03 21:54:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 723 bytes |
| コンパイル時間 | 2,131 ms |
| コンパイル使用メモリ | 195,832 KB |
| 最終ジャッジ日時 | 2025-02-11 02:25:28 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
string S;
cin>>S;
int N=S.size();
if(N==1){
cout<<S<<'\n';
return 0;
}
string ans="";
for(int i=(N+1)/2;i<N;i++){
string T=S;
bool ok=true;
for(int j=i-1,k=0;j>=0;j--,k++){
if(i+k>=N)T.push_back(S[j]);
else if(S[j]!=S[i+k])ok=false;
}
if(ok&&(ans==""||ans.size()>T.size())){
ans=T;
}
}
for(int i=N/2;i<N;i++){
string T=S;
bool ok=true;
for(int j=i-1,k=1;j>=0;j--,k++){
if(i+k>=N)T.push_back(S[j]);
else if(S[j]!=S[i+k])ok=false;
}
if(ok&&(ans==""||ans.size()>T.size())){
ans=T;
}
}
cout<<ans<<'\n';
}