結果
問題 | No.599 回文かい |
ユーザー | firiexp |
提出日時 | 2019-12-07 22:34:33 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,426 bytes |
コンパイル時間 | 1,145 ms |
コンパイル使用メモリ | 105,816 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-08 00:48:16 |
合計ジャッジ時間 | 2,702 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | WA | - |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 66 ms
5,376 KB |
testcase_11 | AC | 38 ms
5,376 KB |
testcase_12 | AC | 73 ms
5,376 KB |
testcase_13 | AC | 43 ms
5,376 KB |
testcase_14 | AC | 107 ms
5,376 KB |
testcase_15 | AC | 122 ms
5,376 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
evil_0.txt | WA | - |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <map> #include <set> #include <queue> #include <stack> #include <numeric> #include <bitset> #include <cmath> #include <chrono> static const int MOD = 1000000007; using ll = long long; using namespace std; template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208; using u64 = unsigned long long; constexpr u64 M = (1UL << 61) - 1; constexpr u64 POSITIVISER = M * 3; constexpr u64 MASK30 = (1UL << 30) - 1; constexpr u64 MASK31 = (1UL << 31) - 1; class rolling_hash_u64 { static u64 get_base(){ u64 z = 37; return z; } static u64 &B() { static u64 B_ = (get_base())%(M-2)+2; return B_; } static vector<u64> &p() { static vector<u64> p_{1, B()}; return p_; } static inline u64 mul(u64 x, u64 y){ u64 a = x >> 31, b = x & MASK31, c = y >> 31, d = y & MASK31, e = b*c+a*d; return (a*c << 1) + b*d + ((e & MASK30) << 31) + (e >> 30); } static inline u64 calc_mod(u64 val){ val = (val & M) + (val >> 61); if(val > M) val -= M; return val; } public: vector<u64> hash; explicit rolling_hash_u64(const string &s) { if(p().size() <= s.size()){ int l = p().size(); p().resize(s.size()+1); for (int i = l; i < p().size(); ++i) { p()[i] = calc_mod(mul(p()[i-1], p()[1])); } } hash.resize(s.size()+1, 0); for (int i = 0; i < s.size(); ++i) { hash[i+1] = calc_mod(mul(hash[i],B()) + s[i]); } }; u64 get(int l, int r){ return calc_mod(hash[r] + POSITIVISER - mul(hash[l], p()[r-l])); } }; template<ll M = 1000000007> struct modint{ ll val; modint(): val(0){} template<typename T> explicit modint(T t){val = t%M; if(val < 0) val += M;} modint pow(ll k){ modint res(1), x(val); while(k){ if(k&1) res *= x; x *= x; k >>= 1; } return res; } template<typename T> modint& operator=(T a){ val = a%M; if(val < 0) val += M; return *this; } modint inv() {return pow(M-2);} modint& operator+=(modint a){ val += a.val; if(val >= M) val -= M; return *this;} modint& operator-=(modint a){ val += M-a.val; if(val >= M) val -= M; return *this;} modint& operator*=(modint a){ val = 1LL*val*a.val%M; return *this;} modint& operator/=(modint a){ return (*this) *= a.inv();} modint operator+(modint a) const {return modint(val) +=a;} modint operator-(modint a) const {return modint(val) -=a;} modint operator*(modint a) const {return modint(val) *=a;} modint operator/(modint a) const {return modint(val) /=a;} modint operator-(){ return modint(-val);} bool operator==(const modint a) const {return val == a.val;} bool operator!=(const modint a) const {return val != a.val;} bool operator<(const modint a) const {return val < a.val;} }; using mint = modint<MOD>; int main() { string s; cin >> s; rolling_hash_u64 h(s); int n = s.size(), m = n/2; vector<mint> dp(m+1); dp[0] = 1; for (int i = 0; i < m; ++i) { for (int j = 0; j <= i; ++j) { if(h.get(j, i+1) == h.get(n-i-1, n-j)) dp[i+1] += dp[j]; } } cout << accumulate(dp.begin(),dp.end(), mint(0)).val << "\n"; return 0; }