結果
| 問題 |
No.599 回文かい
|
| コンテスト | |
| ユーザー |
shung11260
|
| 提出日時 | 2019-10-15 18:07:13 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 2,335 bytes |
| コンパイル時間 | 732 ms |
| コンパイル使用メモリ | 65,160 KB |
| 実行使用メモリ | 814,720 KB |
| 最終ジャッジ日時 | 2024-12-29 23:22:19 |
| 合計ジャッジ時間 | 9,837 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 TLE * 1 MLE * 3 |
ソースコード
#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;
vector<long long int> memd;
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) {
// dp[0]=1;
// if(rh.get(0, rh.size()/2)==rh.get((rh.size()+1)/2, rh.size())) {
// dp_sum[1] += dp[0];
// }
// for(int i=1; i<rh.size()/2+1; i++) {
// dp[i] += 1;
// cout << rh.size()/2-i << "-" << rh.size()/2-i+1\
// << " <-> " << (rh.size()+1)/2+i-1 << "-" << (rh.size()+1)/2+i << endl;
// if(rh.get(rh.size()/2-i, rh.size()/2-i+1)==rh.get((rh.size()+1)/2+i-1, (rh.size()+1)/2+i)) {
// cout << i << endl;
// dp[i] += dp[i-1];
// }
// if(rh.get(0, rh.size()/2-i)==rh.get((rh.size()+1)/2+i, rh.size())) {
// dp_sum[i+1] += dp_sum[i]+dp[i];
// }
// }
// return dp_sum[rh.size()/2+1];
// }
long long int count_kaibunkai(RollingHush rh, int left, int right) {
long long int count=1;
if(right-left<=1) {
memd[left]=1;
return memo[left]=count;
}
if(memd[left]) {
return memo[left];
}
int l=left+1, r=right-1;
while(l<=r) {
if(rh.get(left, l)==rh.get(r, right)) {
count += count_kaibunkai(rh, l, r)%MOD;
}
l++;
r--;
}
memd[left]=1;
return memo[left]=count%MOD;
}
int main() {
string str;
cin >> str;
memo.assign(str.size()/2+1, 0);
memd.assign(str.size()/2+1, 0);
RollingHush rh_str(str);
cout << count_kaibunkai(rh_str, 0, str.size()) << endl;
return 0;
}
shung11260