結果

問題 No.1617 Palindrome Removal
ユーザー srjywrdnprkt
提出日時 2024-03-15 11:51:52
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 689 bytes
コンパイル時間 1,738 ms
コンパイル使用メモリ 193,920 KB
最終ジャッジ日時 2025-02-20 04:30:38
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    //aabb->N
    //aaabaaa -> N-2
    //aaabbaaa -> N-2
    //aaa -> -1
    //aaaa ->0
    //aza -> -1

    string S;
    cin >> S;
    int N = S.size();

    for (int i=0; i<N/2; i++){
        if (S[i] != S[N-1-i]){
            cout << N << endl;
            return 0;
        }
    }

    if (N == 3){
        cout << -1 << endl;
        return 0;
    }

    for (int i=0; i<N; i++){
        if (S[i] != S[0]){
            cout << N-2 << endl;
            return 0;
        }
    }

    cout << (N % 2 == 1 ? -1 : 0) << endl;

    return 0;
}
0