結果

問題 No.1617 Palindrome Removal
ユーザー umezo
提出日時 2021-07-22 21:31:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 625 bytes
コンパイル時間 1,757 ms
コンパイル使用メモリ 193,584 KB
最終ジャッジ日時 2025-01-23 06:11:54
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  string s;
  cin>>s;
  
  int n=s.size();
  
  if(n==1){
    cout<<-1<<endl;
    return 0;
  }
  
  string t=s;
  reverse(ALL(t));
  
  bool b=false;
  for(int i=1;i<n;i++){
    if(s[i]!=s[0]) b=true;
  }
  
  if(s!=t) cout<<n<<endl;
  else if(b){
    if(n==3) cout<<-1<<endl;
    else cout<<n-2<<endl;
  }
  else{
    if(n%2==0) cout<<0<<endl;
    else cout<<-1<<endl;
  }
  
  
  
  
    
  return 0;
}
0