結果

問題 No.515 典型LCP
ユーザー square1001square1001
提出日時 2017-05-05 23:04:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 319 ms / 1,000 ms
コード長 1,044 bytes
コンパイル時間 2,802 ms
コンパイル使用メモリ 73,136 KB
実行使用メモリ 17,952 KB
最終ジャッジ日時 2023-10-12 11:04:16
合計ジャッジ時間 4,935 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 230 ms
17,952 KB
testcase_01 AC 307 ms
17,952 KB
testcase_02 AC 319 ms
14,436 KB
testcase_03 AC 4 ms
8,128 KB
testcase_04 AC 4 ms
8,148 KB
testcase_05 AC 123 ms
14,360 KB
testcase_06 AC 128 ms
14,524 KB
testcase_07 AC 123 ms
14,616 KB
testcase_08 AC 130 ms
14,388 KB
testcase_09 AC 186 ms
14,480 KB
testcase_10 AC 96 ms
14,480 KB
testcase_11 AC 100 ms
14,448 KB
testcase_12 AC 101 ms
14,512 KB
testcase_13 AC 241 ms
14,388 KB
testcase_14 AC 20 ms
14,512 KB
testcase_15 AC 133 ms
14,088 KB
testcase_16 AC 138 ms
13,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
const int mod1 = 1000000439;
const int mod2 = 1000000637;
const int bs = 100000969;
int N, M, a, b, c[100009]; long long x, d; char s[800009]; vector<int> h1[100009], h2[100009];
int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%s", s);
		while (s[c[i]]) c[i]++;
		h1[i].resize(c[i] + 1);
		h2[i].resize(c[i] + 1);
		for (int j = 0; j < c[i]; j++) {
			h1[i][j + 1] = (1LL * h1[i][j] * bs + s[j]) % mod1;
			h2[i][j + 1] = (1LL * h2[i][j] * bs + s[j]) % mod2;
		}
	}
	scanf("%d %lld %lld", &M, &x, &d);
	long long t = 1LL * N * (N - 1), ret = 0;
	for (int i = 1; i <= M; i++) {
		int a = x / (N - 1), b = x % (N - 1);
		if (a > b) swap(a, b);
		else b++;
		int l = 0, r = min(c[a], c[b]) + 1;
		while (r - l > 1) {
			int m = (l + r) >> 1;
			if (h1[a][m] == h1[b][m] && h2[a][m] == h2[b][m]) l = m;
			else r = m;
		}
		ret += l;
		x = (x + d >= t ? x + d - t : x + d);
	}
	printf("%lld\n", ret);
	return 0;
}
0