結果
問題 | No.599 回文かい |
ユーザー | pop_o |
提出日時 | 2024-09-22 15:51:13 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,881 bytes |
コンパイル時間 | 2,280 ms |
コンパイル使用メモリ | 207,680 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-22 15:51:18 |
合計ジャッジ時間 | 4,569 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 53 ms
6,944 KB |
testcase_12 | AC | 102 ms
6,940 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
evil_0.txt | WA | - |
ソースコード
#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 b inline 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 + hash2 inline 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/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+1 < n-i; j++) { if (h.get(i, j) == h.get(n-1-j, n-1-i)) { dp[j] += dp[i]; dp[j] %= mod; } } } long long ans = 0; for (int i = 0; i <= n/2; i++) { ans += dp[i]; ans %= mod; } if (s[n/2] == '~') ans -= dp[n/2]; cout << ans << "\n"; // for (int i = 0; i <= n; i++) cout << dp[i] << (i == n? "\n": " "); }