結果

問題 No.515 典型LCP
ユーザー tottoripapertottoripaper
提出日時 2017-05-05 23:25:16
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,466 bytes
コンパイル時間 1,918 ms
コンパイル使用メモリ 170,988 KB
実行使用メモリ 16,836 KB
最終ジャッジ日時 2024-09-14 09:14:17
合計ジャッジ時間 5,042 ms
ジャッジサーバーID
(参考情報)
judge6 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12 WA * 3
権限があれば一括ダウンロードができます

ソースコード

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[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][0] != Ss[j][0]){return 0;}
    if(Ss[i].size() > Ss[j].size()){swap(i, j);}

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

    return lb + 1;
}

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