結果
| 問題 |
No.599 回文かい
|
| ユーザー |
TangentDay
|
| 提出日時 | 2017-11-24 22:54:58 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1,018 ms / 4,000 ms |
| コード長 | 2,357 bytes |
| コンパイル時間 | 612 ms |
| コンパイル使用メモリ | 85,460 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-27 07:46:01 |
| 合計ジャッジ時間 | 5,285 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1e9 + 7;
struct RollingHash{
int n;
ll mod1 = 1e9 + 7, mod2 = 1e9 + 9;
ll base1 = 1007, base2 = 1009;
VL hash1, hash2, pow1, pow2;
void init(string s){
n = s.length();
hash1.assign(n+1, 0);
hash2.assign(n+1, 0);
pow1.assign(n+1, 1);
pow2.assign(n+1, 1);
REP(i,n){
hash1[i+1] = (hash1[i] * base1 + s[i]) % mod1;
hash2[i+1] = (hash2[i] * base2 + s[i]) % mod2;
pow1[i+1] = (pow1[i] * base1) % mod1;
pow2[i+1] = (pow2[i] * base2) % mod2;
}
}
// [l, r)
PL hash(int l, int r){
ll h1 = ((hash1[r] - hash1[l] * pow1[r-l]) % mod1 + mod1) % mod1;
ll h2 = ((hash2[r] - hash2[l] * pow2[r-l]) % mod2 + mod2) % mod2;
return PL(h1, h2);
}
bool match(int l1, int r1, int l2, int r2){
if (r1 > n || r2 > n) return false;
return hash(l1, r1) == hash(l2, r2);
}
bool match(int l1, int l2, int k){
return match(l1, l1 + k, l2, l2 + k);
}
int lcp(int l1, int l2){
int ok = 0, ng = n;
while (ng - ok > 1){
int m = (ok + ng) / 2;
if (match(l1, l2, m)) ok = m;
else ng = m;
}
return ok;
}
};
int main() {
string s;
cin >> s;
int n = s.length();
RollingHash rh;
rh.init(s);
VL dp(n+1);
dp[0] = 1;
REP(i,n/2 + 1){
FOR(l,1,n-i){
if (i + l > n/2) break;
if (rh.match(i,n-i-l,l)){
dp[i+l] = (dp[i+l] + dp[i]) % mod;
}
}
}
// REP(i,n) cout << dp[i];
// cout << endl;
ll ans = 0;
REP(i,n/2+1) ans += dp[i];
cout << ans % mod << endl;
return 0;
}
TangentDay