結果

問題 No.599 回文かい
ユーザー takuwwwotakuwwwo
提出日時 2019-11-16 00:09:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,989 bytes
コンパイル時間 2,139 ms
コンパイル使用メモリ 114,384 KB
実行使用メモリ 404,188 KB
最終ジャッジ日時 2023-10-25 03:45:44
合計ジャッジ時間 4,908 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,872 KB
testcase_01 AC 2 ms
5,884 KB
testcase_02 AC 3 ms
7,944 KB
testcase_03 AC 3 ms
5,876 KB
testcase_04 AC 6 ms
22,320 KB
testcase_05 AC 5 ms
18,224 KB
testcase_06 AC 6 ms
20,272 KB
testcase_07 AC 6 ms
22,320 KB
testcase_08 AC 6 ms
22,320 KB
testcase_09 AC 5 ms
18,224 KB
testcase_10 AC 105 ms
226,776 KB
testcase_11 AC 64 ms
199,700 KB
testcase_12 MLE -
testcase_13 AC 68 ms
210,176 KB
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 AC 4 ms
10,028 KB
testcase_19 AC 3 ms
10,028 KB
testcase_20 AC 3 ms
10,028 KB
evil_0.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;

const ll mod = 1000000007;
const ll mod2 = LONG_LONG_MAX / 30;
ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return pow(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}

class RollingHash{
public:
    map<ll, int> hash;
    RollingHash(){
    }

    void add(ll hash_num){
        if(hash.find(hash_num) == hash.end()){
            hash[hash_num] = 1;
        }
        else {
            hash[hash_num] += 1;
        }
    }

    int search(ll hash_num){
        if(hash.find(hash_num) == hash.end()){
            return 0;
        }
        else{
            return hash[hash_num];
        }
    }
};

ll hashList[5100][5100];
ll hashList2[5100][5100];
vector<ll> modList;

int main(){
    ll dp[10100];

    string s;
    cin >> s;

    fill(dp, dp+5100, 0);
    dp[0] = 1;

    modList.push_back(1);
    for(int i = 0; i < 5100; i++){
        modList.push_back((modList[i] * 26) % mod2);
    }
    for(int i = 0; i < s.length() / 2; i++){
        hashList[i][i] = 0;
        hashList2[i][i] = 0;
        for(int j = 0; j < i+1; j++){
            ll hash1 = hashList[i][j];
            ll hash2 = hashList2[i][j];
            hash1 = ((hash1 * 26) + (s[i] - 'a')) % mod2;
            hash2 = ((s[s.length() - 1 - i] - 'a') * modList[i-j] + hash2) % mod2;

            if(hash1 == hash2){
                dp[i+1] = add(dp[i+1], dp[j]);
            }
            hashList[i+1][j] = hash1;
            hashList2[i+1][j] = hash2;
        }
    }

    ll res = 0;
    for(int i = 0; i <= s.length() / 2; i++){
        res = add(res, dp[i]);
    }
    cout << res << endl;


    return 0;
}


0