結果

問題 No.599 回文かい
ユーザー ミドリムシミドリムシ
提出日時 2017-11-24 23:17:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,020 bytes
コンパイル時間 641 ms
コンパイル使用メモリ 77,516 KB
実行使用メモリ 818,048 KB
最終ジャッジ日時 2024-05-05 11:31:58
合計ジャッジ時間 2,372 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 MLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
evil_0.txt -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 %= 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;
}
0