結果

問題 No.515 典型LCP
ユーザー 37zigen37zigen
提出日時 2017-05-05 23:49:19
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,789 bytes
コンパイル時間 2,156 ms
コンパイル使用メモリ 75,596 KB
実行使用メモリ 136,020 KB
最終ジャッジ日時 2023-10-12 10:32:49
合計ジャッジ時間 16,144 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 WA -
testcase_03 AC 123 ms
56,184 KB
testcase_04 AC 122 ms
55,816 KB
testcase_05 AC 633 ms
117,392 KB
testcase_06 AC 651 ms
117,608 KB
testcase_07 AC 609 ms
118,044 KB
testcase_08 AC 646 ms
117,588 KB
testcase_09 AC 690 ms
117,408 KB
testcase_10 AC 582 ms
118,128 KB
testcase_11 AC 576 ms
117,720 KB
testcase_12 AC 579 ms
118,468 KB
testcase_13 WA -
testcase_14 AC 469 ms
69,552 KB
testcase_15 AC 686 ms
117,360 KB
testcase_16 AC 800 ms
117,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;
import java.util.concurrent.SynchronousQueue;

class Main {
	int N, M;
	int[] X, Y;

	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String[] s = new String[N];
		for (int i = 0; i < N; ++i) {
			s[i] = sc.next();
		}
		long M = sc.nextLong();
		long x = sc.nextLong();
		long d = sc.nextLong();
		long[] i_ = new long[(int) M];
		long[] j_ = new long[(int) M];
		for (int k = 0; k < M; ++k) {
			i_[k] = (x / (N - 1)) + 1;
			j_[k] = (x % (N - 1)) + 1;
			if (i_[k] > j_[k]) {
				long tmp = i_[k];
				i_[k] = j_[k];
				j_[k] = tmp;
			} else {
				j_[k] = j_[k] + 1;
			}
			x = (x + d) % (N * (N - 1));
		}
		long p1 = 1_000_000_000 + 7;
		// long p2 = 1_000_00 + 9;
		long[][] id1 = new long[N][];
		long[][] id2 = new long[N][];
		for (int i = 0; i < N; ++i) {
			id1[i] = new long[s[i].length()];
			id2[i] = new long[s[i].length()];
			for (int j = 0; j < s[i].length(); ++j) {
				id1[i][j] = (j - 1 >= 0 ? id1[i][j - 1] : 0) * p1 + (s[i].charAt(j) - 'a');
				// id2[i][j] = (j - 1 >= 0 ? id2[i][j - 1] : 0) * p2 +
				// (s[i].charAt(j) - 'a');
				id2[i][j] = (j - 1 >= 0 ? (id2[i][j - 1] << 1) : 0) + (s[i].charAt(j) - 'a');
			}
		}

		int ans = 0;
		for (int k = 0; k < M; ++k) {
			int i = (int) (i_[k]) - 1;
			int j = (int) (j_[k]) - 1;

			int l = 0;
			int r = 1 + Math.min(s[i].length(), s[j].length());
			while (r - l > 1) {
				int m = (l + r) / 2;
				if (id1[i][m - 1] == id1[j][m - 1] && id2[i][m - 1] == id2[j][m - 1]) {
					l = m;
				} else {
					r = m;
				}
			}
			ans += l;
		}
		System.out.println(ans);

	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
0