結果
| 問題 |
No.1617 Palindrome Removal
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-04 05:18:28 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 841 bytes |
| コンパイル時間 | 2,301 ms |
| コンパイル使用メモリ | 212,836 KB |
| 最終ジャッジ日時 | 2025-01-23 14:00:24 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 |
ソースコード
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
string s; cin >> s;
int n=s.size();
bool per=true;
for(int i=0;i<n;i++){
if(s[i]!=s[n-1-i])per=false;
}
if(!per){
printf("%d\n",n);
}
else{
for(char c:s){
if(c!=s[0])per=false;
}
if(per){
if(n%2==0)printf("0\n");
else printf("-1\n");
}
else{
if(n==3){
printf("-1\n");
}
else{
printf("%d\n",n-2);
}
}
}
}