結果

問題 No.515 典型LCP
ユーザー parukiparuki
提出日時 2017-05-06 12:02:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,095 bytes
コンパイル時間 2,950 ms
コンパイル使用メモリ 172,740 KB
実行使用メモリ 44,964 KB
最終ジャッジ日時 2023-10-12 15:00:18
合計ジャッジ時間 7,095 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 776 ms
28,540 KB
testcase_06 TLE -
testcase_07 AC 708 ms
28,472 KB
testcase_08 TLE -
testcase_09 TLE -
testcase_10 AC 462 ms
28,420 KB
testcase_11 AC 391 ms
28,424 KB
testcase_12 AC 392 ms
28,400 KB
testcase_13 TLE -
testcase_14 AC 32 ms
28,912 KB
testcase_15 AC 784 ms
28,448 KB
testcase_16 AC 815 ms
28,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

struct RollingHash {
    static const int C = 31, C2 = 29, P = 1000000007, P2 = 1000000009;
    int _n;
    vector<long long> pw, pw2, hs, hs2;

    RollingHash() {}
    RollingHash(const string &st)
        :_n((int)st.size()), pw(_n + 1), pw2(_n + 1), hs(_n + 1), hs2(_n + 1)
    {
        pw[0] = pw2[0] = 1;
        rep(i, _n) {
            pw[i + 1] = (pw[i] * C) % P;
            pw2[i + 1] = (pw2[i] * C2) % P2;
            hs[i + 1] = (C*hs[i] + st[i]) % P;
            hs2[i + 1] = (C2*hs2[i] + st[i]) % P2;
        }
    }

    // [l, r)
    pii getHash(int l, int r) {
        int res, res2;
        res = (hs[r] - hs[l] * pw[r - l]) % P;
        res2 = (hs2[r] - hs2[l] * pw2[r - l]) % P2;
        if (res < 0)res += P;
        if (res2 < 0)res2 += P2;
        return mp(res, res2);
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N;
    cin >> N;
    vector<RollingHash> rhs(N);
    vi len(N);
    rep(i, N) {
        string s;
        cin >> s;
        rhs[i] = RollingHash(s);
        len[i] = sz(s);
    }

    ll M, x, d, ans = 0;
    cin >> M >> x >> d;
    while (M--) {
        ll l = (x / (N - 1)) + 1, r = (x % (N - 1)) + 1;
        if (l > r)swap(l, r);
        else r++;
        x = (x + d) % (N*(N - 1ll));
        --l; --r;
        int lb = 0, ub = min(len[l], len[r]) + 1, mid;
        while (ub - lb > 1) {
            mid = (lb + ub) / 2;
            (rhs[l].getHash(0, mid) == rhs[r].getHash(0, mid) ? lb : ub) = mid;
        }
        ans += lb;
    }
    cout << ans << endl;
}
0