結果

問題 No.515 典型LCP
ユーザー square1001square1001
提出日時 2017-05-05 22:54:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,114 bytes
コンパイル時間 1,037 ms
コンパイル使用メモリ 73,308 KB
実行使用メモリ 39,020 KB
最終ジャッジ日時 2023-10-12 10:02:57
合計ジャッジ時間 5,148 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 WA -
testcase_03 AC 5 ms
11,740 KB
testcase_04 AC 5 ms
11,692 KB
testcase_05 AC 135 ms
38,636 KB
testcase_06 AC 142 ms
38,688 KB
testcase_07 AC 135 ms
38,688 KB
testcase_08 AC 144 ms
38,552 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 142 ms
38,404 KB
testcase_16 AC 152 ms
38,296 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[3000009], b[3000009]; 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);
		int c = 0; while (s[c]) c++;
		h1[i].resize(c + 1);
		h2[i].resize(c + 1);
		for (int j = 0; j < c; 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 = N * (N - 1), ret = 0;
	for (int i = 1; i <= M; i++) {
		a[i] = x / (N - 1);
		b[i] = x - 1LL * a[i] * (N - 1);
		if (a[i] > b[i]) swap(a[i], b[i]);
		else b[i]++;
		x = (x + d >= t ? x + d - t : x + d);
		int s = min(h1[a[i]].size(), h1[b[i]].size()), l = 0, r = s + 1;
		while (r - l > 1) {
			int m = (l + r) >> 1;
			if (h1[a[i]][m] == h1[b[i]][m] && h2[a[i]][m] == h2[b[i]][m]) l = m;
			else r = m;
		}
		ret += l;
	}
	printf("%lld\n", ret);
	return 0;
}
0