結果
| 問題 |
No.599 回文かい
|
| コンテスト | |
| ユーザー |
goodbaton
|
| 提出日時 | 2019-02-20 11:47:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 180 ms / 4,000 ms |
| コード長 | 1,736 bytes |
| コンパイル時間 | 996 ms |
| コンパイル使用メモリ | 98,968 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-06 10:01:37 |
| 合計ジャッジ時間 | 2,480 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <cassert>
typedef long long ll;
using namespace std;
#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
out << "{" << p.first << ", " << p.second << "}";
return out;
}
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
out << '{';
for (const T &item : v) out << item << ", ";
out << "\b\b}";
return out;
}
#endif
#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010
/* Zalgorithm */
// A[i] := S と S[i:|S|-1] の最長共通接頭辞の長さ
void Zalgorithm(const char *S, int *A){
int i = 1, j = 0, k, n = strlen(S);
A[0] = n;
while (i < n) {
while (i+j < n && S[j] == S[i+j]) j++;
A[i] = j;
if (j == 0) { i++; continue; }
for (k = 1; i+k < n && k+A[k] < j; k++) A[i+k] = A[k];
i += k; j -= k;
}
}
ll dp[SIZE];
int a[SIZE];
int main(){
char s[SIZE];
int n;
scanf("%s", s);
n = strlen(s);
dp[0] = 1;
for(int i=0;i<n/2;i++){
Zalgorithm(s+i, a+i);
for(int j=0;i+j<n/2;j++)
if(a[n-1-i-j] > j)
dp[i+j+1] = (dp[i+j+1] + dp[i]) % mod;
}
ll ans = 0;
for(int i=0;i<=n/2;i++)
ans += dp[i];
cout << ans % mod << endl;
return 0;
}
goodbaton