結果

問題 No.515 典型LCP
ユーザー TakatenTakaten
提出日時 2017-05-06 00:55:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,073 bytes
コンパイル時間 1,671 ms
コンパイル使用メモリ 172,864 KB
実行使用メモリ 16,772 KB
最終ジャッジ日時 2023-10-12 11:18:14
合計ジャッジ時間 7,020 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 309 ms
10,604 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 310 ms
10,592 KB
testcase_06 AC 357 ms
10,392 KB
testcase_07 AC 299 ms
10,396 KB
testcase_08 AC 358 ms
10,656 KB
testcase_09 AC 287 ms
11,316 KB
testcase_10 AC 102 ms
11,388 KB
testcase_11 AC 98 ms
11,224 KB
testcase_12 AC 97 ms
11,388 KB
testcase_13 AC 354 ms
10,408 KB
testcase_14 AC 23 ms
10,436 KB
testcase_15 AC 300 ms
10,248 KB
testcase_16 AC 368 ms
10,240 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;

    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