結果

問題 No.599 回文かい
ユーザー mamekinmamekin
提出日時 2017-11-24 22:43:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,484 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 104,324 KB
実行使用メモリ 5,328 KB
最終ジャッジ日時 2023-08-18 04:55:37
合計ジャッジ時間 3,083 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

void ZAlgorithm(const string& s, vector<int>& len)
{
    int n = s.size();
    int i = 1;
    int j = 0;

    len.resize(n);
    len[0] = n;
    while(i < n){
        while(i+j < n && s[j] == s[i+j])
            ++j;
        len[i] = j;
        if(j == 0){
            ++ i;
            continue;
        }

        int k = 1;
        while (i+k < n && k+len[k] < j){
            len[i+k] = len[k];
            ++ k;
        }
        i += k;
        j -= k;
    }
}

const int MOD = 1000000007;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    
    int ans = 0;
    vector<int> dp((n+1)/2, 0);
    dp[0] = 1;
    for(int i=0; i<(n+1)/2; ++i){
        ans += dp[i];
        ans %= MOD;

        int m = n - 2 * i;
        string t = s.substr(i, m);
        vector<int> len;
        ZAlgorithm(t, len);
        for(int j=0; j<m/2; ++j){
            if(len[m-1-j] == j + 1){
                dp[i+j+1] += dp[i];
                dp[i+j+1] %= MOD;
            }
        }
    }
    cout << ans << endl;

    return 0;
}
0