結果

問題 No.1617 Palindrome Removal
ユーザー milanis48663220milanis48663220
提出日時 2021-07-22 22:07:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,323 bytes
コンパイル時間 2,678 ms
コンパイル使用メモリ 121,044 KB
実行使用メモリ 5,208 KB
最終ジャッジ日時 2023-09-24 17:09:26
合計ジャッジ時間 2,531 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,376 KB
testcase_01 AC 7 ms
4,376 KB
testcase_02 AC 8 ms
5,064 KB
testcase_03 AC 8 ms
5,208 KB
testcase_04 AC 12 ms
5,164 KB
testcase_05 AC 10 ms
4,528 KB
testcase_06 AC 32 ms
5,160 KB
testcase_07 AC 20 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 28 ms
4,896 KB
testcase_11 AC 24 ms
4,928 KB
testcase_12 AC 29 ms
5,184 KB
testcase_13 AC 29 ms
5,144 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

bool judge(string s){
    int n = s.size();
    for(int i = 0; i < n; i++){
        if(s[i] != s[n-i-1]) return false;
    }
    return true;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    set<char> st;
    string s; cin >> s;
    if(s.size() <= 1){
        cout << -1 << endl;
        return 0;
    }
    for(char c: s) st.insert(c);
    if(st.size() == 1){
        if(s.size()%2 == 0) cout << 0 << endl;
        else cout << -1 << endl;
        return 0;
    }
    if(judge(s)){
        if(s.size() == 3) cout << -1 << endl;
        else cout << s.size()-2 << endl;
    }else{
        cout << s.size() << endl;
    }
}
0