結果

問題 No.599 回文かい
ユーザー NekosyndromeNekosyndrome
提出日時 2017-11-24 22:54:20
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,006 bytes
コンパイル時間 1,547 ms
コンパイル使用メモリ 160,268 KB
実行使用メモリ 401,152 KB
最終ジャッジ日時 2024-05-05 11:16:57
合計ジャッジ時間 14,656 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 3 ms
5,632 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 4 ms
5,760 KB
testcase_08 AC 3 ms
5,632 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 132 ms
215,424 KB
testcase_11 AC 78 ms
132,480 KB
testcase_12 AC 194 ms
242,048 KB
testcase_13 AC 108 ms
146,304 KB
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 AC 3 ms
7,760 KB
testcase_19 AC 3 ms
7,884 KB
testcase_20 AC 4 ms
9,932 KB
evil_0.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 10005
#define MOD 1000000007
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
int n,dp[M][M];
char in[M];
bool pal[M][M];
int calc(int l,int r)
{
	if(l>r) return 1;
	if(dp[l][r]!=-1) return dp[l][r];
	int &res = dp[l][r];
	res = 1;

	string ll="", rr="";
	for(int i=l; i<=n/2; i++) {
		int j = r-(i-l);
		ll = ll + in[i];
		rr = in[j] + rr;
		if(ll==rr)
		{
			res += calc(i+1, j-1);
			if(res>=MOD) res-=MOD;
		}
	}
	return res;
}
int main()
{
	while(~scanf("%s",in+1))
	{
		n = strlen(in+1);
		REP(i,0,n)REP(j,0,n) dp[i][j] = -1;

		printf("%d\n", calc(1,n));
	}
	return 0;
}


0