結果
| 問題 |
No.599 回文かい
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-11-24 23:06:35 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 91 ms / 4,000 ms |
| コード長 | 1,125 bytes |
| コンパイル時間 | 1,707 ms |
| コンパイル使用メモリ | 157,444 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-27 07:58:17 |
| 合計ジャッジ時間 | 2,836 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#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;
}