結果

問題 No.515 典型LCP
ユーザー tottoripapertottoripaper
提出日時 2017-05-05 23:20:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,431 bytes
コンパイル時間 1,687 ms
コンパイル使用メモリ 169,120 KB
実行使用メモリ 16,736 KB
最終ジャッジ日時 2023-10-12 10:17:43
合計ジャッジ時間 7,731 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 451 ms
15,764 KB
testcase_03 AC 5 ms
8,916 KB
testcase_04 AC 5 ms
8,904 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 321 ms
15,772 KB
testcase_10 AC 128 ms
15,840 KB
testcase_11 AC 124 ms
15,984 KB
testcase_12 AC 124 ms
15,880 KB
testcase_13 AC 414 ms
15,980 KB
testcase_14 AC 16 ms
15,880 KB
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int N;
string Ss[100100];
vector<ll> hs[100100];
const ll P = 252521011ll, Q = 1111110001ll;

void generateHash(){
    for(int i=0;i<N;++i){
        int l = Ss[i].size();
        hs[i].resize(l);

        ll x = 0;
        for(int j=0;j<l;++j){
            x = (x + P * (Ss[i][j] - 'a') % Q) % Q;
            hs[i][j] = x;
        }
    }
}

int calc(int i, int j){
    if(Ss[i].size() > Ss[j].size()){swap(i, j);}

    int l = Ss[i].size();
    int lb = 0, ub = l + 1;
    while(ub - lb > 1){
        int mid = (lb + ub) / 2;
        if(hs[i][mid-1] == hs[j][mid-1]){lb = mid;}
        else{ub = mid;}
    }

    return lb;
}

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

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> Ss[i];
    }

    generateHash();

    ll M, x, d;
    std::cin >> M >> x >> d;

    ll res = 0;
    for(int _=0;_<M;++_){
        int i, j;
        i = (x / (N - 1)) + 1;
        j = (x % (N - 1)) + 1;
        if (i > j){
            swap(i, j);
        }else{
            j = j + 1;
        }
        x = (x + d) % (N * (N - 1));

        res += calc(i - 1, j - 1);
    }

    std::cout << res << std::endl;
}
0