結果
問題 |
No.599 回文かい
|
ユーザー |
![]() |
提出日時 | 2019-10-13 19:22:40 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,790 bytes |
コンパイル時間 | 786 ms |
コンパイル使用メモリ | 64,504 KB |
実行使用メモリ | 302,732 KB |
最終ジャッジ日時 | 2024-12-16 08:41:29 |
合計ジャッジ時間 | 46,934 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 5 WA * 7 TLE * 8 MLE * 2 |
ソースコード
#include <iostream> #include <string> #include <vector> const long long int MOD=1e9+7; const long long int BASE=31; using namespace std; vector<long long int> memo; struct RollingHush { vector<long long int> hash; vector<long long int> power; string str; RollingHush(string s) : hash(s.size()+1), power(s.size()+1) { str=s; hash[0]=0; power[0]=1; for(int si=0; si<s.size(); si++) { long long int s2lli=s[si]; s2lli %= BASE; hash[si+1] = (hash[si]*BASE+s2lli)%MOD; power[si+1] = power[si]*BASE%MOD; } } long long int get(int left, int right) { return ((hash[right]-hash[left]*power[right-left])%MOD+MOD)%MOD; } int size() { return str.size(); } }; long long int count_kaibunkai(RollingHush rh, int left, int right, int cur) { long long int count=1; if(right-left<=1) { return count; } int mid=(left+right)/2; while(left<mid) { if(rh.get(left, mid)==rh.get(right+left-mid, right)) { if(cur>0 && mid<=rh.size()/2 && rh.size()/2<=right+left-mid) { if(rh.size()/2-mid<=cur) { count += memo[cur-1]; } else { memo.push_back(count_kaibunkai(rh, mid, right+left-mid, cur+1)); count += memo[cur]; } mid--; continue; } count += count_kaibunkai(rh, mid, right+left-mid, cur+1); } mid--; } return count; } int main() { string str; cin >> str; RollingHush rh_str(str); memo.push_back(1); cout << count_kaibunkai(rh_str, 0, str.size(), 0) << endl; return 0; }