結果

問題 No.962 LCPs
ユーザー polylogKpolylogK
提出日時 2019-12-22 12:16:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 689 bytes
コンパイル時間 380 ms
コンパイル使用メモリ 86,848 KB
実行使用メモリ 87,332 KB
最終ジャッジ日時 2023-10-12 03:15:31
合計ジャッジ時間 10,949 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
70,996 KB
testcase_01 AC 76 ms
71,228 KB
testcase_02 AC 93 ms
75,472 KB
testcase_03 AC 84 ms
71,012 KB
testcase_04 AC 83 ms
71,120 KB
testcase_05 AC 80 ms
71,124 KB
testcase_06 AC 78 ms
71,124 KB
testcase_07 AC 82 ms
71,140 KB
testcase_08 AC 83 ms
71,128 KB
testcase_09 AC 81 ms
71,144 KB
testcase_10 AC 80 ms
71,124 KB
testcase_11 AC 77 ms
71,132 KB
testcase_12 AC 76 ms
71,116 KB
testcase_13 AC 77 ms
71,156 KB
testcase_14 AC 75 ms
71,236 KB
testcase_15 AC 75 ms
70,764 KB
testcase_16 AC 75 ms
71,180 KB
testcase_17 AC 194 ms
87,332 KB
testcase_18 AC 156 ms
83,020 KB
testcase_19 AC 157 ms
82,688 KB
testcase_20 AC 143 ms
80,900 KB
testcase_21 AC 140 ms
80,972 KB
testcase_22 AC 138 ms
80,068 KB
testcase_23 AC 137 ms
80,268 KB
testcase_24 AC 131 ms
79,716 KB
testcase_25 AC 133 ms
79,660 KB
testcase_26 AC 128 ms
78,548 KB
testcase_27 AC 144 ms
80,344 KB
testcase_28 AC 135 ms
79,476 KB
testcase_29 AC 137 ms
78,904 KB
testcase_30 AC 141 ms
80,180 KB
testcase_31 AC 158 ms
81,224 KB
testcase_32 AC 134 ms
78,532 KB
testcase_33 AC 168 ms
82,640 KB
testcase_34 AC 141 ms
79,424 KB
testcase_35 AC 142 ms
79,524 KB
testcase_36 AC 139 ms
80,296 KB
testcase_37 AC 138 ms
78,668 KB
testcase_38 AC 137 ms
78,768 KB
testcase_39 AC 134 ms
78,616 KB
testcase_40 AC 134 ms
79,244 KB
testcase_41 AC 138 ms
78,756 KB
testcase_42 AC 133 ms
78,524 KB
testcase_43 AC 134 ms
78,224 KB
testcase_44 AC 129 ms
78,436 KB
testcase_45 AC 139 ms
79,104 KB
testcase_46 AC 140 ms
78,352 KB
testcase_47 AC 78 ms
71,196 KB
testcase_48 AC 77 ms
71,184 KB
testcase_49 AC 77 ms
71,148 KB
testcase_50 AC 76 ms
71,132 KB
testcase_51 AC 81 ms
71,516 KB
testcase_52 AC 78 ms
71,012 KB
testcase_53 AC 79 ms
71,184 KB
testcase_54 AC 75 ms
71,128 KB
testcase_55 AC 76 ms
70,764 KB
testcase_56 AC 77 ms
71,136 KB
testcase_57 AC 101 ms
76,364 KB
testcase_58 AC 102 ms
76,508 KB
testcase_59 AC 102 ms
76,080 KB
testcase_60 AC 92 ms
76,072 KB
testcase_61 AC 93 ms
76,120 KB
testcase_62 AC 93 ms
76,344 KB
testcase_63 AC 177 ms
84,040 KB
testcase_64 AC 76 ms
71,508 KB
testcase_65 AC 175 ms
84,100 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