結果

問題 No.515 典型LCP
ユーザー TakatenTakaten
提出日時 2017-05-08 16:33:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,425 bytes
コンパイル時間 1,769 ms
コンパイル使用メモリ 172,080 KB
実行使用メモリ 26,812 KB
最終ジャッジ日時 2023-10-12 19:04:41
合計ジャッジ時間 9,301 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 397 ms
16,772 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 356 ms
17,492 KB
testcase_10 AC 156 ms
17,528 KB
testcase_11 AC 150 ms
17,604 KB
testcase_12 AC 150 ms
17,548 KB
testcase_13 AC 413 ms
16,820 KB
testcase_14 AC 32 ms
16,864 KB
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

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);
    vector<vector<unsigned long long>> hh2(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        hh[i].resize(s[i].size() + 1);
        hh2[i].resize(s[i].size() + 1);
        hh[i][0] = 0;
        hh2[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;
            hh2[i][j + 1] = hh2[i][j] * h + s[i][j];
            hh2[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] && hh2[i][mid] == hh2[i][mid]) {
                l = mid;
            } else {
                r = mid;
            }
        }

        sum += l;
    }

    cout << sum << endl;

    return 0;
}
0