結果

問題 No.515 典型LCP
ユーザー 👑 rin204rin204
提出日時 2022-10-02 18:23:54
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,838 bytes
コンパイル時間 6,022 ms
コンパイル使用メモリ 306,796 KB
実行使用メモリ 23,672 KB
最終ジャッジ日時 2023-08-26 16:10:36
合計ジャッジ時間 12,780 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 227 ms
23,308 KB
testcase_06 AC 292 ms
23,252 KB
testcase_07 AC 237 ms
23,240 KB
testcase_08 AC 359 ms
23,180 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 201 ms
23,064 KB
testcase_16 AC 202 ms
23,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<atcoder/string>
#include<atcoder/segtree>
using namespace std;
using namespace atcoder;

using S = int;

S op(S l, S r){
    if(l <= r) return l;
    else return r;
}

S e(){
    return 1 << 30;
}

void solve(){
    int n;
    cin >> n;
    vector<int> le;
    int ind = 0;
    string S;
    for(int i = 0; i < n; i++){
        le.push_back(ind);
        string s;
        cin >> s;
        S += s;
        ind += s.size();
    }
    auto sa = suffix_array(S);
    auto lcp = lcp_array(S, sa);
    vector<int> inv(ind);
    for(int i = 0; i < ind; i++){
        inv[sa[i]] = i;
    }
    vector<int> pos(n);
    vector<int> lst;
    for(int i = 0; i < n; i++){
        int l = le[i];
        pos[i] = inv[l];
        lst.push_back(inv[l]);
    }

    sort(lst.begin(), lst.end());
    map<int, int> mp;
    vector<int> A;
    for(int i = 0; i < n; i++){
        int l = lst[i];
        mp[l] = i;
        if(i != 0){
            int mi = 1 << 30;
            for(int j = lst[i - 1]; j < l; j++){
                mi = min(mi, lcp[j]);
            }
            A.push_back(mi);
        }
    }

    for(int i = 0; i < n; i++){
        pos[i] = mp[pos[i]];
    }

    segtree<int, op, e> seg(A);

    int m;
    long long x, d;
    cin >> m >> x >> d;
    long long ans = 0;
    while(m--){
        int i = x / (n - 1);
        int j = x - i * (n - 1);        
        if(i > j) swap(i, j);
        else j++;
        
        int l = pos[i];
        int r = pos[j];
        if(l > r) swap(l, r);
        ans += seg.prod(l, r);
        x = (x + d) % (n * (n - 1));
    }
    cout << ans << "\n";
}


int main(){
    cin.tie(0)->sync_with_stdio(0);
    int t;
    t = 1;
    // cin >> t;
    while(t--) solve();
}




0