結果

問題 No.1617 Palindrome Removal
ユーザー 山D山D
提出日時 2021-07-29 18:49:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 644 bytes
コンパイル時間 561 ms
コンパイル使用メモリ 70,340 KB
実行使用メモリ 5,172 KB
最終ジャッジ日時 2023-10-12 17:03:12
合計ジャッジ時間 2,040 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
4,348 KB
testcase_01 AC 21 ms
5,172 KB
testcase_02 AC 20 ms
4,348 KB
testcase_03 AC 19 ms
4,352 KB
testcase_04 AC 21 ms
5,068 KB
testcase_05 AC 16 ms
4,352 KB
testcase_06 AC 21 ms
5,068 KB
testcase_07 AC 13 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 19 ms
4,352 KB
testcase_11 AC 17 ms
4,352 KB
testcase_12 AC 21 ms
5,108 KB
testcase_13 AC 22 ms
5,156 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
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%2){
    if(same){
      cout<<-1;
    }
  else if(kaibun){
    if(n>3)
    cout<<n-2;
  else
    cout<<-1;
  }else{
    cout<<n;
  }

  }else{
  if(same){
    cout<<0;
  }else if(kaibun){
    cout<<n-2;
  }else{
    cout<<n;
  }
}cout<<endl;
}
0