結果

問題 No.515 典型LCP
ユーザー TakatenTakaten
提出日時 2017-05-08 16:28:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,282 bytes
コンパイル時間 1,612 ms
コンパイル使用メモリ 171,100 KB
実行使用メモリ 16,512 KB
最終ジャッジ日時 2023-10-12 19:02:33
合計ジャッジ時間 7,712 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 349 ms
10,564 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,356 KB
testcase_05 AC 353 ms
10,412 KB
testcase_06 WA -
testcase_07 AC 338 ms
10,360 KB
testcase_08 AC 413 ms
10,364 KB
testcase_09 AC 330 ms
11,100 KB
testcase_10 AC 140 ms
11,408 KB
testcase_11 AC 136 ms
11,220 KB
testcase_12 AC 136 ms
11,216 KB
testcase_13 AC 402 ms
10,364 KB
testcase_14 AC 26 ms
10,372 KB
testcase_15 AC 335 ms
10,240 KB
testcase_16 AC 424 ms
10,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const unsigned long long h = 1000000007;
const unsigned long long h2 = 1000000009;
const unsigned long long h3 = 1000000021;

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    vector<vector<unsigned long long>> hh(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        hh[i].resize(s[i].size() + 1);
        hh[i][0] = 0;
        for (int j = 0; j < s[i].size(); j++) {
            hh[i][j + 1] = hh[i][j] * h + s[i][j];
            hh[i][j + 1] %= h2;
            hh[i][j + 1] = hh[i][j] * h + s[i][j];
            hh[i][j + 1] %= h3;
        }
    }
    long long m, x, d;
    cin >> m >> x >> d;

    unsigned long long sum = 0;
    for (int k = 1; k <= m; k++) {
        int i, j;
        i = (x / (n - 1));
        j = (x % (n - 1));
        if (i > j) {
            swap(i, j);
        } else {
            j++;
        }
        x = (x + d) % (n * (n - 1));

        int l = 0;
        int r = min(s[i].size(), s[j].size()) + 1;
        while (r - l > 1) {
            int mid = (l + r) / 2;
            if (hh[i][mid] == hh[j][mid]) {
                l = mid;
            } else {
                r = mid;
            }
        }

        sum += l;
    }

    cout << sum << endl;

    return 0;
}
0