結果

問題 No.1617 Palindrome Removal
ユーザー 山D山D
提出日時 2021-07-29 18:42:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 526 bytes
コンパイル時間 538 ms
コンパイル使用メモリ 68,836 KB
実行使用メモリ 5,216 KB
最終ジャッジ日時 2023-10-12 16:57:51
合計ジャッジ時間 2,028 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 22 ms
5,028 KB
testcase_02 AC 19 ms
4,352 KB
testcase_03 AC 20 ms
4,364 KB
testcase_04 AC 21 ms
5,168 KB
testcase_05 AC 17 ms
4,352 KB
testcase_06 AC 20 ms
5,028 KB
testcase_07 AC 12 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 18 ms
4,352 KB
testcase_11 AC 17 ms
4,364 KB
testcase_12 AC 21 ms
5,216 KB
testcase_13 AC 21 ms
5,164 KB
testcase_14 AC 1 ms
4,356 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 WA -
testcase_23 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
using namespace std;
#define rep(i,s,n) for (int i=s;i<n;i++)
int main(){

  string S;cin>>S;
  int n=S.length();
  int bef=S[0];
  bool kaibun=true,same=true;
  rep(i,0,n/2){
    if(S[i]!=S[n-1-i]){
      kaibun=same=false;
      break;
    }
    if(bef!=S[i] || bef!=S[n-1-i]){
      same=false;
    }
    bef=S[i];
  }
  if((n%2)&&bef!=S[n/2])same=false;
  if(!(n>1)){
    cout<<-1;
  }else if(same){
    cout<<0;
  }else if(kaibun){
    cout<<n-2;
  }else{
    cout<<n;
  }cout<<endl;
}
0