結果

問題 No.599 回文かい
ユーザー TangentDayTangentDay
提出日時 2017-11-24 22:53:47
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,315 bytes
コンパイル時間 622 ms
コンパイル使用メモリ 81,104 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 05:02:46
合計ジャッジ時間 18,673 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const ll mod = 1e9 + 7;

struct RollingHash{
    int n;
    ll mod1 = 1e9 + 7, mod2 = 1e9 + 9;
    ll base1 = 1007, base2 = 1009;
    VL hash1, hash2, pow1, pow2;

    void init(string s){
        n = s.length();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        pow1.assign(n+1, 1);
        pow2.assign(n+1, 1);
        REP(i,n){
            hash1[i+1] = (hash1[i] * base1 + s[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + s[i]) % mod2;
            pow1[i+1] = (pow1[i] * base1) % mod1;
            pow2[i+1] = (pow2[i] * base2) % mod2;
        }
    }

    // [l, r)
    PL hash(int l, int r){
        ll h1 = ((hash1[r] - hash1[l] * pow1[r-l]) % mod1 + mod1) % mod1;
        ll h2 = ((hash2[r] - hash2[l] * pow2[r-l]) % mod2 + mod2) % mod2;
        return PL(h1, h2);
    }

    bool match(int l1, int r1, int l2, int r2){
        if (r1 > n || r2 > n) return false;
        return hash(l1, r1) == hash(l2, r2);
    }

    bool match(int l1, int l2, int k){
        return match(l1, l1 + k, l2, l2 + k);
    }

    int lcp(int l1, int l2){
        int ok = 0, ng = n;
        while (ng - ok > 1){
            int m = (ok + ng) / 2;
            if (match(l1, l2, m)) ok = m;
            else ng = m;
        }
        return ok;
    }
};

int main() {
    string s;
    cin >> s;
    int n = s.length();

    RollingHash rh;
    rh.init(s);

    VL dp(n+1);
    dp[0] = 1;
    REP(i,n){
        FOR(l,1,n-i){
            if (rh.match(i,n-i-l,l)){
                dp[i+l] = (dp[i+l] + dp[i]) % mod;
            }
        }
    }

    // REP(i,n) cout << dp[i];
    // cout << endl;

    ll ans = 0;
    REP(i,n/2+1) ans += dp[i];
    cout << ans % mod << endl;

    return 0;
}



0