結果
| 問題 | No.1617 Palindrome Removal | 
| コンテスト | |
| ユーザー |  yumaru | 
| 提出日時 | 2021-07-22 21:31:26 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 24 ms / 2,000 ms | 
| コード長 | 1,396 bytes | 
| コンパイル時間 | 1,880 ms | 
| コンパイル使用メモリ | 193,936 KB | 
| 最終ジャッジ日時 | 2025-01-23 06:11:25 | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 20 | 
ソースコード
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i = a; i < b; i++)
#define rrep(i,a,b) for (int i = a - 1; i >= b; i--)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define pvec(a) for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << '\n'
#define dbwt(a) cout << fixed << setprecision(15) << a << '\n'
using namespace std;
using ll = long long;
void wt() {cout << endl;}
template<class T, class U>bool chmin(T& a, U b) {if (a > b) {a = b; return 1;} return 0;}
template<class T, class U>bool chmax(T& a, U b) {if (a < b) {a = b; return 1;} return 0;}
template<class T, class U>long long llceil(T a, U b) {return (long long)(a + b - 1) / b;}
template<class H, class...T>void wt(H&& h, T&&... t){cout<<h<<" "; wt(forward<T>(t)...);}
//-------------------------------------------------------------------------------------//
int main() {
    string S;
    cin >> S;
    int N = S.size();
    
    bool kaibun = true;
    rep (i, 0, N / 2) {
        if (S[i] != S[N - i - 1]) kaibun = false;
    }
    bool allsame = *min_element(rng(S)) == *max_element(rng(S));
    if (!kaibun) wt(N);
    else if (allsame) {
        if (N % 2 == 1) wt(-1);
        else wt(0);
    }
    else {
        if (N == 3 && S[0] == S[2]) wt(-1);
        else wt(N - 2);
    }
    return 0;
}
            
            
            
        