結果

問題 No.962 LCPs
ユーザー polylogKpolylogK
提出日時 2019-12-22 12:15:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 954 ms / 2,000 ms
コード長 689 bytes
コンパイル時間 656 ms
コンパイル使用メモリ 11,016 KB
実行使用メモリ 19,988 KB
最終ジャッジ日時 2023-10-12 03:13:27
合計ジャッジ時間 15,447 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,820 KB
testcase_01 AC 16 ms
7,808 KB
testcase_02 AC 21 ms
8,376 KB
testcase_03 AC 19 ms
8,336 KB
testcase_04 AC 18 ms
7,756 KB
testcase_05 AC 17 ms
7,760 KB
testcase_06 AC 18 ms
7,808 KB
testcase_07 AC 18 ms
7,856 KB
testcase_08 AC 18 ms
7,776 KB
testcase_09 AC 17 ms
7,884 KB
testcase_10 AC 18 ms
7,848 KB
testcase_11 AC 17 ms
7,992 KB
testcase_12 AC 16 ms
7,860 KB
testcase_13 AC 16 ms
7,760 KB
testcase_14 AC 16 ms
7,860 KB
testcase_15 AC 16 ms
7,860 KB
testcase_16 AC 17 ms
7,960 KB
testcase_17 AC 954 ms
19,096 KB
testcase_18 AC 534 ms
19,988 KB
testcase_19 AC 532 ms
19,960 KB
testcase_20 AC 385 ms
16,188 KB
testcase_21 AC 385 ms
16,024 KB
testcase_22 AC 310 ms
13,980 KB
testcase_23 AC 313 ms
14,132 KB
testcase_24 AC 262 ms
13,012 KB
testcase_25 AC 266 ms
12,944 KB
testcase_26 AC 232 ms
12,272 KB
testcase_27 AC 352 ms
14,828 KB
testcase_28 AC 250 ms
12,516 KB
testcase_29 AC 223 ms
11,620 KB
testcase_30 AC 311 ms
13,764 KB
testcase_31 AC 387 ms
13,852 KB
testcase_32 AC 208 ms
11,600 KB
testcase_33 AC 533 ms
19,584 KB
testcase_34 AC 254 ms
12,472 KB
testcase_35 AC 268 ms
12,296 KB
testcase_36 AC 287 ms
11,808 KB
testcase_37 AC 186 ms
10,428 KB
testcase_38 AC 195 ms
10,456 KB
testcase_39 AC 190 ms
10,500 KB
testcase_40 AC 187 ms
10,464 KB
testcase_41 AC 188 ms
10,480 KB
testcase_42 AC 187 ms
10,432 KB
testcase_43 AC 184 ms
10,404 KB
testcase_44 AC 190 ms
10,504 KB
testcase_45 AC 190 ms
10,556 KB
testcase_46 AC 188 ms
10,460 KB
testcase_47 AC 16 ms
8,580 KB
testcase_48 AC 17 ms
8,420 KB
testcase_49 AC 17 ms
8,448 KB
testcase_50 AC 17 ms
8,564 KB
testcase_51 AC 16 ms
8,524 KB
testcase_52 AC 16 ms
8,432 KB
testcase_53 AC 17 ms
8,428 KB
testcase_54 AC 17 ms
8,400 KB
testcase_55 AC 17 ms
8,460 KB
testcase_56 AC 17 ms
8,440 KB
testcase_57 AC 203 ms
8,432 KB
testcase_58 AC 204 ms
8,376 KB
testcase_59 AC 199 ms
8,480 KB
testcase_60 AC 87 ms
8,400 KB
testcase_61 AC 89 ms
8,608 KB
testcase_62 AC 89 ms
8,488 KB
testcase_63 AC 522 ms
15,300 KB
testcase_64 AC 17 ms
8,676 KB
testcase_65 AC 509 ms
15,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python

if __name__ == '__main__':
	N = int(input())
	S = [input() for i in range(N)]

	a = [0 for i in range(N - 1)]
	for i in range(N - 1):
		tmp = min(len(S[i]), len(S[i + 1]))
		for j in range(tmp):
			if S[i][j] != S[i + 1][j]:
				break

			a[i] = j + 1

	ans = 0
	for s in S:
		ans += len(s)
	
	nxt = [len(a) for i in range(len(a))]
	for i in range(len(a) - 1, -1, -1):
		now = i + 1
		while now < len(a):
			if a[now] < a[i]:
				break

			now = nxt[now]
		nxt[i] = now

	for i in range(len(a)):
		now = i
		while now < len(a) and a[now] > 0:
			S, T = now - i + 2, nxt[now] - i + 1
			L = (S + T) * (T - S + 1) // 2

			ans += L * a[now]
			now = nxt[now]

	print(ans)
0