結果

問題 No.599 回文かい
ユーザー mtsdmtsd
提出日時 2017-11-24 23:40:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 992 bytes
コンパイル時間 506 ms
コンパイル使用メモリ 73,656 KB
実行使用メモリ 34,304 KB
最終ジャッジ日時 2024-05-05 11:43:21
合計ジャッジ時間 6,522 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007

bool ok[6000][6000];
ll dp[5010];

int main(){
	string s;
	cin >> s;
	int n = (int)s.size();
	if(n%2==0){
		s.insert(s.begin()+n/2,'-');
		n++;
	}
	int m = (n-1)/2;
	for(int i=0;i<m;i++){
		for(int j=0;j<m;j++){
			if(j+i>m)break;
			if(i==0){
				if(s[j]==s[n-1-j]){
					ok[j][j] = 1;
				}
			}else{
				bool flag = 1;
				for(int k=0;k<=i;k++){
					if(s[j+k]!=s[n-j-1-i+k]){
						flag = 0;
						break;
					}
				}
				if(flag){
					ok[j][j+i] = 1;
				}
			}
		}
	}
	dp[m] = 1;
	for(int i=m-1;i>=0;i--){
		dp[i] = 1;
		for(int j=i;j<=m-1;j++){
			if(ok[i][j]==1){
				dp[i] += dp[j+1];
			}
		}
	}
	cout << dp[0] << endl;
	return 0;
}
0