結果

問題 No.273 回文分解
ユーザー beet
提出日時 2018-08-03 15:01:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 955 bytes
コンパイル時間 1,480 ms
コンパイル使用メモリ 169,808 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-19 17:23:11
合計ジャッジ時間 2,608 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE

Int calc(string s){
  Int n=s.size();
  Int res=0;
  for(Int i=0;i<=n;i++){
    for(Int j=0;j<i;j++){
      string t=s.substr(j,i-j);
      string u=t;
      reverse(u.begin(),u.end());
      if(u==t) chmax(res,i-j);
    }
  }
  return res;
}
signed main(){
  string s;
  cin>>s;
  {
    string t=s;
    string u=t;
    reverse(u.begin(),u.end());
    if(u!=t) return cout<<calc(s)<<endl,0;
  }
  Int ans=s.size();
  {
    string t=s.substr(1);
    string u=t;
    reverse(u.begin(),u.end());
    if(u==t) return cout<<ans-1<<endl,0;
  }
  {
    string t=s.substr(0,s.size()-1);
    string u=t;
    reverse(u.begin(),u.end());
    if(u==t) return cout<<ans-1<<endl,0;
   }
  cout<<ans-2<<endl;
  return 0;
}
0