結果
問題 | No.599 回文かい |
ユーザー | firiexp |
提出日時 | 2019-12-07 23:23:46 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,699 bytes |
コンパイル時間 | 974 ms |
コンパイル使用メモリ | 107,728 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-08 01:46:57 |
合計ジャッジ時間 | 2,515 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 1 ms
6,940 KB |
testcase_10 | AC | 64 ms
5,376 KB |
testcase_11 | AC | 38 ms
5,376 KB |
testcase_12 | AC | 75 ms
5,376 KB |
testcase_13 | AC | 44 ms
5,376 KB |
testcase_14 | AC | 104 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 | WA | - |
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 = (static_cast<uint64_t>((chrono::system_clock::now().time_since_epoch().count())&((1LL << 32)-1)))+0x9e3779b97f4a7c15; z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9; z = (z ^ (z >> 27)) * 0x94d049bb133111eb; z = (z % (M-2))+1; 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; }