結果

問題 No.515 典型LCP
ユーザー tottoripapertottoripaper
提出日時 2017-05-06 00:03:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,653 bytes
コンパイル時間 1,642 ms
コンパイル使用メモリ 169,512 KB
実行使用メモリ 26,980 KB
最終ジャッジ日時 2023-10-12 10:37:52
合計ジャッジ時間 7,718 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 AC 6 ms
11,180 KB
testcase_04 AC 5 ms
11,248 KB
testcase_05 AC 126 ms
24,664 KB
testcase_06 WA -
testcase_07 AC 127 ms
24,944 KB
testcase_08 WA -
testcase_09 AC 376 ms
25,272 KB
testcase_10 AC 185 ms
25,256 KB
testcase_11 AC 206 ms
25,268 KB
testcase_12 AC 212 ms
25,236 KB
testcase_13 AC 427 ms
24,648 KB
testcase_14 AC 38 ms
24,652 KB
testcase_15 AC 120 ms
24,372 KB
testcase_16 AC 132 ms
24,288 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 = 33455171ll;

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 >> 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;++_){
        ll 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