結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 808 ms
26,740 KB
testcase_02 TLE -
testcase_03 AC 6 ms
11,028 KB
testcase_04 AC 5 ms
11,004 KB
testcase_05 AC 109 ms
24,516 KB
testcase_06 WA -
testcase_07 AC 112 ms
24,576 KB
testcase_08 WA -
testcase_09 AC 421 ms
24,216 KB
testcase_10 AC 179 ms
24,600 KB
testcase_11 AC 204 ms
24,524 KB
testcase_12 AC 205 ms
24,460 KB
testcase_13 AC 411 ms
24,496 KB
testcase_14 AC 26 ms
24,528 KB
testcase_15 AC 111 ms
24,332 KB
testcase_16 AC 123 ms
24,300 KB
権限があれば一括ダウンロードができます

ソースコード

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};

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

void generateHash(const ll p, vector<ll> (&hs)[100100]){
    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') % MOD) % MOD;
            hs[i][j] = x;
        }
    }
}

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

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

        if(res == -1 || lb + 1 < res){
            res = lb + 1;
        }
    }

    return res;
}

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(P, hs[0]);
    generateHash(Q, hs[1]);

    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