結果

問題 No.515 典型LCP
ユーザー e869120e869120
提出日時 2017-05-05 22:47:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,172 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 79,132 KB
実行使用メモリ 19,912 KB
最終ジャッジ日時 2023-10-12 09:59:55
合計ジャッジ時間 5,765 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 464 ms
19,876 KB
testcase_01 AC 498 ms
19,912 KB
testcase_02 WA -
testcase_03 AC 5 ms
10,388 KB
testcase_04 AC 5 ms
10,528 KB
testcase_05 AC 207 ms
17,944 KB
testcase_06 AC 214 ms
17,740 KB
testcase_07 AC 207 ms
17,800 KB
testcase_08 AC 217 ms
17,676 KB
testcase_09 AC 207 ms
18,316 KB
testcase_10 AC 168 ms
18,292 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 206 ms
17,720 KB
testcase_14 AC 17 ms
17,480 KB
testcase_15 AC 189 ms
17,484 KB
testcase_16 AC 195 ms
17,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;
#pragma warning(disable:4996)
long long N, M, x, d, sum; string S[100009]; vector<long long>E[100009];
char c[10000009];

bool compare(long long a1, long long a2, long long a3) {
	if (S[a1].size() < a3 || S[a2].size() < a3)return false;
	if (E[a1][a3] == E[a2][a3])return true;
	return false;
}

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		scanf("%s", c);
		int pos = 0; while (c[pos]) { S[i] += c[pos]; pos++; }
		E[i].resize(S[i].size() + 2, 0);
		long long Y = 1;
		for (int j = 1; j <= S[i].size(); j++) {
			E[i][j] = E[i][j - 1] + (Y*(long long)(S[i][j - 1])); Y *= 256;
		}
	}
	cin >> M >> x >> d;
	for (int i = 1; i <= M; i++) {
		long long A = (x / (N - 1)) + 1;
		long long B = (x % (N - 1)) + 1;
		if (A > B)swap(A, B);
		else B = B + 1;
		x = (x + d) % (N * (N - 1));

		long long L = 0, R = 1000000, M;
		while (true) {
			M = (L + R) / 2;
			bool p1 = compare(A, B, M), p2 = compare(A, B, M + 1);
			if (p1 == true && p2 == false)break;
			else if (p1 == false)R = M;
			else L = M;
		}
		sum += M;
	}
	cout << sum << endl;
	return 0;
}
0