結果

問題 No.1617 Palindrome Removal
ユーザー SSRS
提出日時 2021-07-22 21:35:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 542 bytes
コンパイル時間 1,465 ms
コンパイル使用メモリ 168,308 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-17 16:45:10
合計ジャッジ時間 2,735 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 18 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  string S2 = S;
  reverse(S2.begin(), S2.end());
  if (S != S2){
    cout << S.size() << endl;
  } else if (S.size() == 1){
    cout << -1 << endl;
  } else {
    bool ok = true;
    for (int i = 0; i < S.size(); i++){
      if (S[i] != S[0]){
        ok = false;
      }
    }
    if (ok){
      if (S.size() % 2 == 0){
        cout << 0 << endl;
      } else {
        cout << -1 << endl;
      }
    } else {
      cout << S.size() - 2 << endl;
    }
  }
}
0