結果

問題 No.515 典型LCP
ユーザー femtofemto
提出日時 2017-05-05 23:43:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 775 ms / 1,000 ms
コード長 1,325 bytes
コンパイル時間 1,485 ms
コンパイル使用メモリ 169,808 KB
実行使用メモリ 27,776 KB
最終ジャッジ日時 2023-10-12 11:10:02
合計ジャッジ時間 10,388 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 695 ms
27,504 KB
testcase_01 AC 693 ms
27,776 KB
testcase_02 AC 775 ms
25,432 KB
testcase_03 AC 5 ms
11,880 KB
testcase_04 AC 5 ms
11,980 KB
testcase_05 AC 501 ms
25,376 KB
testcase_06 AC 517 ms
25,360 KB
testcase_07 AC 495 ms
25,360 KB
testcase_08 AC 521 ms
25,440 KB
testcase_09 AC 680 ms
25,360 KB
testcase_10 AC 199 ms
25,376 KB
testcase_11 AC 185 ms
25,300 KB
testcase_12 AC 184 ms
25,296 KB
testcase_13 AC 525 ms
25,272 KB
testcase_14 AC 21 ms
25,704 KB
testcase_15 AC 548 ms
25,348 KB
testcase_16 AC 629 ms
25,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;


struct RollingHash {
	int n;
	static const unsigned P = 1000000007U;
	vector<unsigned long long> pow, phash;
	RollingHash() {};
	template<typename T>
	RollingHash(const T& s, unsigned long long Q = 1) {
		n = s.size();
		pow.resize(n + 1); phash.resize(n + 1);
		pow[0] = Q; phash[0] = 0;
		for(int i = 0; i < n; i++) {
			pow[i + 1] = pow[i] * P;
			phash[i + 1] = s[i] + phash[i] * P;
		}
	}
	unsigned long long get(int i) const { return phash[i]; }
	unsigned long long get(int i, int j) const { return get(j) - get(i) * pow[j - i]; }
};

RollingHash h[100000];
string s[100000];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll N, M, x, d;
	cin >> N;
	for(int i = 0; i < N; i++) {
		cin >> s[i];
		h[i] = RollingHash(s[i]);
	}
	cin >> M >> x >> d;

	ll ans = 0;
	for(int k = 0; k < M; k++) {
		int i = (x / (N - 1)) + 1;
		int j = (x % (N - 1)) + 1;
		if(i > j) swap(i, j);
		else j++;
		x = (x + d) % (N * (N - 1));
		//cerr << "i : " << i << ", j : " << j << endl;
		i--, j--;
		int ok = 0, ng = min(s[i].size(), s[j].size()) + 1;
		while(abs(ok - ng) > 1) {
			int mid = (ok + ng) / 2;
			if(h[i].get(0, mid) == h[j].get(0, mid)) ok = mid;
			else ng = mid;
		}
		//cerr << "ok : " << ok << endl;
		ans += ok;
	}
	cout << ans << endl;
}
0