結果

問題 No.599 回文かい
ユーザー ukohank517ukohank517
提出日時 2017-11-25 10:15:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,154 bytes
コンパイル時間 1,060 ms
コンパイル使用メモリ 101,072 KB
実行使用メモリ 28,924 KB
最終ジャッジ日時 2024-05-05 12:26:35
合計ジャッジ時間 1,701 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
5,376 KB
testcase_20 WA -
evil_0.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

ll dp[10010];

vector<string> sstr; 

void divide(string s){
  if(s=="")return ;
  for(int i=1;i<=s.size()/2;i++){
    string a = s.substr(0,i);
    string b = s.substr(s.size()-i,i);
    if(a==b){
      sstr.pb(a);
      divide(s.substr(i,s.size()-i-i));
      return;
    }
  }
  sstr.pb(s);
  sstr.pb("");
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  string S;
  cin >> S;

  divide(S);

  
  if(sstr[sstr.size()-1] == ""){
    sstr.erase(sstr.begin()+sstr.size()-1);
    dp[0]=1;
    

    
    reverse(all(sstr));
    for(ll i = 1;i<sstr.size();i++){

      for(ll j = 1; j<i;j++){
	string a="",b="";
	for(ll k = j;k<=i;k++)
	  a+=sstr[k];
	for(ll k = i;k>=j;k--)
	  b+=sstr[k];


	if(a==b) {
	  //if(i == 2) cout << "a" <<  " " << a  << dp[i-j-1] << endl;
	  dp[i]+=dp[i-j-1];
	}
      }
      dp[i]++;
      dp[i] += dp[i-1];
    }
  }

  
  else{

    /*
    reverse(all(sstr));
    dp[0]=1;

    
    for(ll i=1;i<sstr.size();i++){
      for(ll j = 1;j<=i;j++){
	string a="",b="";
	for(ll k = j ;k<=i;k++)
	  a+=sstr[k];
	for(ll k = i;k>=j;k--)
	  b+=sstr[k];
	if(a==b){
	  if((i-j-1) < 0) dp[i]++;
	  else dp[i]+=dp[i-j-1];
	}
      }
      dp[i]++;
    }
    */
  }
  /*
  cout << "---" << endl;
  rep(i,5) cout << dp[i] << endl;
  cout << "---" << endl;
  */
  cout << dp[sstr.size()-1] << endl;
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}
0