結果
問題 |
No.599 回文かい
|
ユーザー |
|
提出日時 | 2017-11-24 23:20:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,038 bytes |
コンパイル時間 | 1,030 ms |
コンパイル使用メモリ | 78,736 KB |
実行使用メモリ | 814,720 KB |
最終ジャッジ日時 | 2024-11-27 08:14:46 |
合計ジャッジ時間 | 12,727 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 WA * 9 RE * 2 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() / 2; i++){ substrings.push_back({}); } for(int i = 0; i <= S.size() / 2; i++){ string substring = ""; for(int j = i; j <= S.size() / 2; 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; }