結果
問題 | No.599 回文かい |
ユーザー | idat_50me |
提出日時 | 2021-01-08 23:32:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 97 ms / 4,000 ms |
コード長 | 4,106 bytes |
コンパイル時間 | 1,952 ms |
コンパイル使用メモリ | 197,232 KB |
最終ジャッジ日時 | 2025-01-17 14:44:06 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
#define PROBLEM "https://yukicoder.me/problems/no/599" #ifndef call_include #define call_include #include <bits/stdc++.h> using namespace std; #endif vector<int> z_algorithm(const string &S) { int N = S.length(); vector<int> res(N, 0); for(int i=1, c=0; i<N; i++) { int l = i-c; if(i+res[l] < c+res[c]) { res[i] = res[l]; } else { int l = max(c+res[c]-i, 0); while(i+l<N && S[l]==S[i+l]) l++; res[i] = l; c = i; } } res[0] = N; return res; } template<int mod> struct mint { private: long long val; public: mint(long long x=0) : val((mod+x%mod)%mod) {} private: mint inv() const { long long x_ = val, xd = 1, xdd = 0, y_ = mod, yd = 0, ydd = 1, div; while(true) { if(!y_) return mint(xd); div = x_/y_; x_ -= div*y_; xd -= div*yd; xdd -= div*ydd; if(!x_) return mint(yd); div = y_/x_; y_ -= div*x_; yd -= div*xd; ydd -= div*xdd; } } public: mint operator-() const { return mint(-val); } mint& operator+=(const mint& a) { val += a.val; if(val >= mod) val -= mod; return *this; } mint& operator-=(const mint& a) { val -= a.val; if(val < 0) val += mod; return *this; } mint& operator*=(const mint& a) { (val*=a.val) %= mod; return *this; } mint& operator/=(const mint& a) { return (*this) *= a.inv(); } mint& operator+=(const long long& a) { (val+=mod+a%mod) %= mod; return *this; } mint& operator-=(const long long& a) { (val+=mod-a%mod) %= mod; return *this; } mint& operator*=(const long long& a) { (val*=mod+a%mod) %= mod; return *this; } mint& operator/=(const long long& a) { return (*this)/=mint(a); } mint operator+(const mint& a) const { mint res(*this); return res+=a; } mint operator-(const mint& a) const { mint res(*this); return res-=a; } mint operator*(const mint& a) const { mint res(*this); return res*=a; } mint operator/(const mint& a) const { mint res(*this); return res/=a; } mint operator+(const long long& a) const { mint res(*this); return res+=a; } mint operator-(const long long& a) const { mint res(*this); return res-=a; } mint operator*(const long long& a) const { mint res(*this); return res*=a; } mint operator/(const long long& a) const { mint res(*this); return res/=mint(a); } mint& operator++() { (++val) %= mod; return *this; } mint operator++(int) { mint res(*this); (++val) %= mod; return res; } mint& operator--() { (val+=mod-1) %= mod; return *this; } mint operator--(int) { mint res(*this); (val+=mod-1) %= mod; return res; } bool operator==(const mint& a) const { return val == a.val; } bool operator!=(const mint& a) const { return val != a.val; } bool operator<(const mint& a) const { return val < a.val; } bool operator>(const mint& a) const { return val > a.val; } bool operator<=(const mint& a) const { return val <= a.val; } bool operator>=(const mint& a) const { return val >= a.val; } bool operator==(const long long& a) const { return val == a; } bool operator!=(const long long& a) const { return val != a; } bool operator<(const long long& a) const { return val < a; } bool operator>(const long long& a) const { return val > a; } bool operator<=(const long long& a) const { return val <= a; } bool operator>=(const long long& a) const { return val >= a; } mint& operator=(const mint& a) { val = a.val; return *this; } mint& operator=(const long long& a) { val = (mod+a%mod)%mod; return *this; } friend ostream& operator<<(ostream& os, const mint& a) { return os << a.val; } friend istream& operator>>(istream& is, mint &a) { long long n; is >> n; a = mint(n); return is; } }; using mi = mint<1000000007>; int main() { string S; cin>>S; vector<mi> dp(S.length()/2+1, 0); dp[0] = 1; for(int i=0; i<=(S.length()-1)/2; i++) { vector<int> v = z_algorithm(string(S.begin()+i, S.end()-i)); for(int j=1; j<=v.size()/2; j++) { if(v[v.size()-j]==j) dp[i+j] += dp[i]; } } cout<<accumulate(dp.begin(), dp.end(), mi(0))<<endl; }