結果

問題 No.599 回文かい
ユーザー uenokuuenoku
提出日時 2017-11-25 01:26:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,281 bytes
コンパイル時間 2,716 ms
コンパイル使用メモリ 164,664 KB
実行使用メモリ 158,200 KB
最終ジャッジ日時 2023-08-18 05:48:48
合計ジャッジ時間 9,260 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
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 #

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
string s;
lli mod = 1e9 + 7;
int n;
lli base[2] = {97, 103};
lli p[2] = {(lli)1e9 + 7, (lli)1e9 + 9};
lli dp[10005][10005] = {};
lli hash_[1005][1005][2] = {};
void fill()
{
    // hash [l,r)
    rep(i, n)
    {
        for (int j = i; j < n; j++) {
            rep(k, 2)
                hash_[i][j + 1][k]
                = (base[k] * hash_[i][j][k] + s[j]) % p[k];
        }
    }
}
lli f(lli l, lli r)
{
    lli ll = l, rr = r;
    if (l >= r)
        return 0;
    //cout << l << " " << r << endl;
    if (dp[l][r] != 0)
        return dp[l][r];
    dp[l][r] = 1;
    rep(i, n)
    {

        if (ll >= rr) {
            break;
        }
        // s l..ll ==  s rr .. r
        bool flag = true;
        rep(k, 2)
        {
            flag &= (hash_[l][ll + 1][k] == hash_[rr - 1][r][k]);
        }
        if (flag)
            dp[l][r] += f(ll + 1, rr - 1);
        dp[l][r] %= mod;

        ll++, rr--;
    }
    return dp[l][r];
}
int main()
{
    cin >> s;
    n = s.size();
    fill();
    // cout << hash_[0][3][1] << endl;
    // cout << hash_[6][9][1] << endl;

    cout << f(0, n) << endl;
}
0