結果

問題 No.1617 Palindrome Removal
ユーザー hiikunZ
提出日時 2021-07-22 21:54:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,304 bytes
コンパイル時間 1,827 ms
コンパイル使用メモリ 195,568 KB
最終ジャッジ日時 2025-01-23 06:36:23
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
        for(ll i = 0;i < N / 2;i++){
            if(A[S[i]] - 'a' == 1){
                cout << N - 2 << endl;
                return 0;
            }
            A[S[i] - 'a'] = 1;
        }
        cout << 0 << endl;
    }
    else{
        ll m = N / 2;
        vector<ll> A(500,0);
        for(ll i = 0;i < m;i++){
            if(A[S[i]] - 'a' == 1){
                cout << N - 2 << endl;
                return 0;
            }
            A[S[i] - 'a'] = 1;
        }
        if(N <= 3){
            cout << -1 << endl;
            return 0;
        }
        if(S[0] == S[m]){
            cout << -1 << endl;
            return 0;
        }
        cout << N - 2 << endl;
        return 0;
    }
}
0