結果

問題 No.1617 Palindrome Removal
ユーザー ぷら
提出日時 2021-07-22 21:24:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 519 bytes
コンパイル時間 2,159 ms
コンパイル使用メモリ 197,952 KB
最終ジャッジ日時 2025-01-23 06:03:53
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    string S;
    cin >> S;
    string T = S;
    reverse(T.begin(),T.end());
    string R = S;
    sort(R.begin(),R.end());
    if(S == T) {
        if(S.size() == 3 || (S.size()%2 && R.front() == R.back())) {
            cout << -1 << endl;
        }
        else if(R.front() == R.back()) {
            cout << 0 << endl;
        }
        else {
            cout << S.size()-2 << endl;
        }
    }
    else {
        cout << S.size() << endl;
    }
}
0