結果

問題 No.515 典型LCP
ユーザー pekempeypekempey
提出日時 2017-05-06 05:43:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,675 bytes
コンパイル時間 452 ms
コンパイル使用メモリ 42,384 KB
実行使用メモリ 107,604 KB
最終ジャッジ日時 2023-10-12 14:11:11
合計ジャッジ時間 7,635 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 171 ms
17,552 KB
testcase_02 AC 163 ms
17,312 KB
testcase_03 AC 7 ms
17,312 KB
testcase_04 AC 8 ms
17,292 KB
testcase_05 AC 473 ms
105,288 KB
testcase_06 AC 668 ms
105,360 KB
testcase_07 AC 597 ms
105,344 KB
testcase_08 AC 700 ms
105,408 KB
testcase_09 AC 57 ms
17,524 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 74 ms
19,688 KB
testcase_14 WA -
testcase_15 AC 268 ms
107,592 KB
testcase_16 AC 269 ms
107,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <algorithm>

constexpr int N = 800001;
constexpr int M = 1 << 21;
char buf[N];
int trie[N][26];
int pos[100000];
bool marked[N];
int eulerID[N];
int now;
int rmq[M * 2];

int readint() {
	int n;
	scanf("%d", &n);
	return n;
}

long long readlong() {
	long long n;
	scanf("%lld", &n);
	return n;
}

void dfs(int u, int depth) {
	eulerID[u] = now;
	rmq[M + now++] = depth;
	for (int i = 0; i < 26; i++) {
		if (!trie[u][i]) {
			continue;
		}
		dfs(trie[u][i], depth + 1);
		rmq[M + now++] = depth;
	}
}

int main() {
	const int n = readint();
	int cnt = 1;
	for (int i = 0; i < n; i++) {
		scanf("%s", buf);
		int u = 0;
		for (int j = 0; buf[j] != 0; j++) {
			char c = buf[j] - 'a';
			if (!trie[u][c]) {
				trie[u][c] = cnt++;
			}
			u = trie[u][c];
		}
		pos[i] = u;
	}
	dfs(0, 0);
	for (int i = M - 1; i >= 1; i--) {
		rmq[i] = std::min(rmq[i * 2], rmq[i * 2 + 1]);
	}
	const int m = readint();
	const long long x = readlong();
	const long long d = readlong();
	int ii = x % (n - 1);
	int jj = x / (n - 1);
	const int di = d % (n - 1);
	const int dj = d / (n - 1);
	long long ans = 0;
	for (int foo = 0; foo < m; foo++) {
		int i = jj;
		int j = ii;
		if (i > j) {
			std::swap(i, j);
		} else {
			j++;
		}
		ii += di;
		if (ii >= n - 1) {
			ii -= n - 1;
			jj++;
		}
		jj += dj;
		if (jj >= n) {
			jj -= n;
		}
		int l = eulerID[pos[i]] + M;
		int r = eulerID[pos[j]] + 1 + M;
		if (l > r) {
			std::swap(l, r);
		}
		int val = 123456789;
		while (l < r) {
			if (l & 1) {
				val = std::min(val, rmq[l++]);
			}
			if (r & 1) {
				val = std::min(val, rmq[--r]);
			}
			l /= 2;
			r /= 2;
		}
		ans += val;
	}
	printf("%lld\n", ans);
}
0