結果

問題 No.599 回文かい
ユーザー NekosyndromeNekosyndrome
提出日時 2017-11-24 23:06:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 151 ms / 4,000 ms
コード長 1,125 bytes
コンパイル時間 1,258 ms
コンパイル使用メモリ 143,972 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 05:10:39
合計ジャッジ時間 2,669 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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
#define MOD2 562949953421311LL
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];
char in[M];
int calc(int l,int r)
{
	if(l>r) return 1;
	if(dp[l]!=-1) return dp[l];
	int &res = dp[l];
	res = 1;

	//string ll="", rr="";
	LL ll=0, rr=0, pw=1;
	for(int i=l; i<=n/2; i++) {
		int j = r-(i-l);
		ll = ll*29 + (in[i]-'a'); ll%=MOD2;
		rr = (in[j]-'a')*pw + rr; rr%=MOD2;
		pw = pw*29; pw%=MOD2;

		//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) dp[i] = -1;

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


0