結果
| 問題 |
No.1617 Palindrome Removal
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-22 21:57:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 2,000 ms |
| コード長 | 1,434 bytes |
| コンパイル時間 | 1,845 ms |
| コンパイル使用メモリ | 197,288 KB |
| 最終ジャッジ日時 | 2025-01-23 06:38:15 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const ll MAX = 5000000000000000000;
const ld PI = 3.14159265358979;
const ll MOD = 0;//2024948111;
ld dotorad(ld K){return PI * K / 180.0;}
ld radtodo(ld K){return K * 180.0 / PI;}
mt19937 mt;
void randinit(){srand((unsigned)time(NULL));mt = mt19937(rand());}
int main(){
string S;
cin >> S;
ll N = S.size();
for(ll i = 0;i < N;i++){
if(S[i] != S[N - 1 - i]){
cout << N << endl;
return 0;
}
}
if(N % 2 == 0){
vector<ll> A(500,0);
ll a = 0;
for(ll i = 0;i < N / 2;i++){
if(A[S[i] - 'a'] == 0){
a++;
A[S[i] - 'a'] = 1;
}
}
if(a >= 2){
cout << N - 2 << endl;
return 0;
}
cout << 0 << endl;
}
else{
ll m = N / 2;
vector<ll> A(500,0);
ll a = 0;
for(ll i = 0;i < m;i++){
if(A[S[i] - 'a'] == 0){
a++;
A[S[i] - 'a'] = 1;
}
}
if(a >= 2){
cout << N - 2 << endl;
return 0;
}
if(N <= 3){
cout << -1 << endl;
return 0;
}
if(S[0] == S[m]){
cout << -1 << endl;
return 0;
}
cout << N - 2 << endl;
return 0;
}
}