結果
| 問題 |
No.599 回文かい
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-12-04 19:37:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 269 ms / 4,000 ms |
| コード長 | 1,070 bytes |
| コンパイル時間 | 2,387 ms |
| コンパイル使用メモリ | 194,908 KB |
| 最終ジャッジ日時 | 2025-01-16 16:01:09 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
typedef long long ll;
const int MOD = 1000000007;
int n;
string s;
int memo[10000];
vector<int> z_algo(string s) {
int c=0, n=s.size();
vector<int> z(n, 0);
for (int i=1; i<n; i++) {
int l = i-c;
if (i+z[l]<c+z[c]) z[i] = z[l];
else {
int j = max(0, c+z[c]-i);
while (i+j<n && s[j]==s[i+j]) j++;
z[i] = j;
c = i;
}
}
z[0] = n;
return z;
}
ll f(int l) {
if (n-2*l==0) return 1;
if (memo[l]!=-1) return memo[l];
vector<int> z = z_algo(s.substr(l, n-2*l));
ll res = 1;
for (int i=n-2*l-1; i>=0; i--) {
int com = n-2*l-i;
if (z[i]==com && 2*com<=n-2*l) res = (res+f(l+com))%MOD;
}
return memo[l] = res;
}
int main() {
//ループ変数が被っていないか?
//制約を確認しているか?
//変数のtypoがないか?
cin.tie(0); ios::sync_with_stdio(false);
cin >> s;
n = s.size();
fill(memo, memo+10000, -1);
cout << f(0) << endl;
}