結果

問題 No.515 典型LCP
ユーザー TakatenTakaten
提出日時 2017-05-06 00:48:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,054 bytes
コンパイル時間 1,570 ms
コンパイル使用メモリ 172,296 KB
実行使用メモリ 16,616 KB
最終ジャッジ日時 2023-10-12 10:56:58
合計ジャッジ時間 6,656 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 WA -
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 304 ms
10,448 KB
testcase_06 AC 341 ms
10,508 KB
testcase_07 AC 289 ms
10,608 KB
testcase_08 AC 347 ms
10,448 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 293 ms
10,236 KB
testcase_16 AC 363 ms
10,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const unsigned long long h = 947239;

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];
        }
    }
    int m, x, d;
    cin >> m >> x >> d;

    int 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());
        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