結果
問題 | No.599 回文かい |
ユーザー |
|
提出日時 | 2024-09-22 15:57:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 112 ms / 4,000 ms |
コード長 | 2,764 bytes |
コンパイル時間 | 2,034 ms |
コンパイル使用メモリ | 200,712 KB |
最終ジャッジ日時 | 2025-02-24 11:32:17 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
#include<bits/stdc++.h>using namespace std;const long long mod = 1000000007;#define dmp(x) cerr << "line " << __LINE__ << " " << #x << " : " << x << "\n"const uint64_t hashmod = 0x1fffffffffffffff;const uint64_t base = chrono::duration_cast<chrono::microseconds>(chrono::system_clock::now().time_since_epoch()).count() % hashmod;const uint64_t mdf = uint64_t(1e17) + 1;template<typename T>struct rolling_hash {int n;vector<uint64_t> hash, p;inline uint64_t mul(uint64_t a, uint64_t b) const {uint64_t a31 = a >> 31, b31 = b >> 31;a &= 0x7fffffffull; b &= 0x7fffffffull;uint64_t x = a * b31 + b * a31;uint64_t res = (a31 * b31 << 1) + (x >> 30) + ((x & 0x3fffffffull) << 31) + a * b;res = (res >> 61) + (res & hashmod);if (res >= hashmod) res -= hashmod;return res;}rolling_hash(const T &a) {n = (int)a.size();hash.assign(n + 1, 0ull);p.assign(n + 1, 0ull);p[0] = 1;for(int i = 0; i < n; i++) {p[i + 1] = mul(p[i], base);hash[i + 1] = mul(hash[i], base) + (mdf + (uint64_t)a[i]);if(hash[i + 1] >= hashmod) hash[i + 1] -= hashmod;}}// get hashing of S[l, r)inline uint64_t get(int l, int r) const {uint64_t res = hash[r] + hashmod - mul(hash[l], p[r - l]);if (res >= hashmod) res -= hashmod;return res;}// return longest common prefixes of a and binline int lcp(const rolling_hash &b, int l1, int r1, int l2, int r2) const {int size = min(r1 - l1, r2 - l2);int ok = 0, ng = size + 1;while(ng - ok > 1) {int mid = (ok + ng) / 2;if(get(l1, l1 + mid) == b.get(l2, l2 + mid)) ok = mid;else ng = mid;}return ok;}// return hash1 + hash2inline uint64_t connect(uint64_t hash1, uint64_t hash2, int hash2size) const {uint64_t res = mul(hash1, p[hash2size]) + hash2;if (res >= hashmod) res -= hashmod;return res;}};int main() {ios::sync_with_stdio(false);cin.tie(nullptr);string s;cin >> s;int n = (int) s.size();if (n % 2 == 0) {s = s.substr(0, n/2) + '~' + s.substr(n/2);n++;}rolling_hash h(s);vector<long long> dp(n+1, 0);dp[0] = 1;for (int i = 0; i <= n/2; i++) {for (int j = i+1; j <= n/2; j++) {if (h.get(i, j) == h.get(n-j, n-i)) {dp[j] += dp[i];dp[j] %= mod;}}}long long ans = 0;for (int i = 1; i <= n/2; i++) {ans += dp[i];ans %= mod;}cout << ++ans%mod << "\n";}