結果
問題 |
No.599 回文かい
|
ユーザー |
|
提出日時 | 2017-11-24 23:04:54 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,007 bytes |
コンパイル時間 | 897 ms |
コンパイル使用メモリ | 77,828 KB |
実行使用メモリ | 814,848 KB |
最終ジャッジ日時 | 2024-11-27 07:56:11 |
合計ジャッジ時間 | 12,554 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 WA * 9 MLE * 9 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> using namespace std; string S; vector<vector<string>> substrings; int dp[5000]; int find(int now){ if(now >= (S.size() + 1) / 2){ return 1; }else if(dp[now] != -1){ return dp[now]; }else{ int 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 %= int(1e9 + 7); } } return dp[now] = ans + 1; } } 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; }