結果

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;


bool is_palindrome(const string &s, char c = '?'){
    auto n = s.length();
    for (int i = 0; i < (n+1)/2; ++i) {
        if(s[i] == c || s[n-i-1] == c) continue;
        if(s[i] != s[n-i-1]) return false;
    }
    return true;
}
int main() {
    string s;
    cin >> s;
    int same = 1;
    int n = s.size();
    for (int i = 0; i+1 < n; ++i) {
        if(s[i] != s[i+1]) same = 0;
    }
    if(same){
        puts(n%2 == 0 ? "0" : "-1");
        return 0;
    }else if(!is_palindrome(s)) {
        cout << n << "\n";
    }else if(n != 3) {
        cout << n-2 << "\n";
    }else {
        cout << -1 << "\n";
    }
    return 0;
}
0