結果

問題 No.1617 Palindrome Removal
ユーザー rogi52rogi52
提出日時 2022-10-03 22:48:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 736 bytes
コンパイル時間 2,104 ms
コンパイル使用メモリ 207,708 KB
実行使用メモリ 6,252 KB
最終ジャッジ日時 2024-06-08 16:17:31
合計ジャッジ時間 3,347 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
6,120 KB
testcase_01 AC 9 ms
6,252 KB
testcase_02 AC 9 ms
6,148 KB
testcase_03 AC 9 ms
6,120 KB
testcase_04 AC 13 ms
6,252 KB
testcase_05 AC 11 ms
5,736 KB
testcase_06 AC 6 ms
6,248 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 30 ms
5,988 KB
testcase_11 AC 25 ms
5,732 KB
testcase_12 AC 31 ms
6,252 KB
testcase_13 AC 34 ms
6,252 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    string s; cin >> s;
    auto is_pal = [](string s) {
        return s == string(s.rbegin(), s.rend());
    };

    if(!is_pal(s)) {
        cout << s.size() << endl;
    } else {
        set<char> st;
        for(char c : s) st.insert(c);
        if(st.size() == 1u) {
            if(s.size() % 2 == 0) {
                cout << 0 << endl;
            } else {
                cout << -1 << endl;
            }
        } else if(s.size() == 3) {
            cout << -1 << endl;
        } else {
            cout << s.size() - 2u << endl;
        }
    }
}
0