結果

問題 No.1617 Palindrome Removal
ユーザー 山D
提出日時 2021-07-29 18:49:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 644 bytes
コンパイル時間 501 ms
コンパイル使用メモリ 67,208 KB
最終ジャッジ日時 2025-01-23 10:11:17
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

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