結果
| 問題 |
No.599 回文かい
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-11-24 23:18:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,023 bytes |
| コンパイル時間 | 890 ms |
| コンパイル使用メモリ | 77,664 KB |
| 実行使用メモリ | 814,848 KB |
| 最終ジャッジ日時 | 2024-11-27 08:12:08 |
| 合計ジャッジ時間 | 12,183 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 WA * 9 MLE * 9 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
string S;
vector<vector<string>> substrings;
long dp[5000];
long find(int now){
if(now >= (S.size() + 1) / 2){
return 1;
}else if(dp[now] != -1){
return dp[now];
}else{
long ans = 0;
for(int i = 0; i + now < S.size() / 2; i++){
if(substrings[i][now] == substrings[i][S.size() - i - now - 1]){
ans += find(i + now + 1);
ans %= 1000000007;
}
}
return dp[now] = (ans + 1) % 1000000007;
}
}
int main(){
cin >> S;
for(int i = 0; i < S.size(); i++){
substrings.push_back({});
}
for(int i = 0; i < S.size(); i++){
string substring = "";
for(int j = i; j < S.size(); j++){
substring.push_back(S[i]);
substrings[substring.size() - 1].push_back(substring);
}
}
for(int i = 0; i < 5000; i++){
dp[i] = -1;
}
cout << find(0) << endl;
}