結果

問題 No.962 LCPs
ユーザー polylogKpolylogK
提出日時 2019-12-22 11:40:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,013 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 74,536 KB
実行使用メモリ 11,780 KB
最終ジャッジ日時 2023-10-12 02:11:19
合計ジャッジ時間 5,576 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 19 ms
11,780 KB
testcase_18 AC 12 ms
7,272 KB
testcase_19 AC 12 ms
7,280 KB
testcase_20 AC 9 ms
6,016 KB
testcase_21 AC 8 ms
6,196 KB
testcase_22 AC 7 ms
5,180 KB
testcase_23 AC 7 ms
5,272 KB
testcase_24 AC 6 ms
4,948 KB
testcase_25 AC 6 ms
4,864 KB
testcase_26 AC 5 ms
4,648 KB
testcase_27 AC 8 ms
5,484 KB
testcase_28 AC 5 ms
4,608 KB
testcase_29 AC 5 ms
4,348 KB
testcase_30 AC 7 ms
5,216 KB
testcase_31 AC 9 ms
5,964 KB
testcase_32 AC 5 ms
4,352 KB
testcase_33 AC 11 ms
7,208 KB
testcase_34 AC 6 ms
4,736 KB
testcase_35 AC 5 ms
4,600 KB
testcase_36 AC 6 ms
4,932 KB
testcase_37 AC 5 ms
4,348 KB
testcase_38 AC 5 ms
4,348 KB
testcase_39 AC 5 ms
4,348 KB
testcase_40 AC 5 ms
4,380 KB
testcase_41 AC 6 ms
4,352 KB
testcase_42 AC 6 ms
4,348 KB
testcase_43 AC 5 ms
4,348 KB
testcase_44 AC 5 ms
4,348 KB
testcase_45 AC 5 ms
4,348 KB
testcase_46 AC 5 ms
4,352 KB
testcase_47 AC 2 ms
4,352 KB
testcase_48 AC 2 ms
4,348 KB
testcase_49 AC 2 ms
4,352 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 2 ms
4,348 KB
testcase_52 AC 1 ms
4,352 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 2 ms
4,352 KB
testcase_56 AC 3 ms
4,348 KB
testcase_57 AC 2 ms
4,352 KB
testcase_58 AC 3 ms
4,348 KB
testcase_59 AC 3 ms
4,348 KB
testcase_60 AC 2 ms
4,352 KB
testcase_61 AC 2 ms
4,348 KB
testcase_62 AC 2 ms
4,352 KB
testcase_63 AC 13 ms
8,856 KB
testcase_64 AC 2 ms
4,348 KB
testcase_65 AC 13 ms
8,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using i64 = std::int_fast64_t;

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

	int n; std::cin >> n; std::vector<std::string> s(n);
	for(int i = 0; i < n; i++) std::cin >> s[i];

	std::vector<i64> a(n - 1);
	for(int i = 0; i < n - 1; i++) {
		for(int j = 0; j < std::min(s[i + 1].size(), s[i].size()); j++) {
			if(s[i][j] != s[i + 1][j]) break;

			a[i] = j + 1;
		}
	}

	i64 ans = 0;
	for(auto v: s) ans += v.size();

	std::vector<int> nxt(a.size());
	for(int i = (int)a.size() - 1; i >= 0; i--) {
		int now = i + 1;
		while(now < a.size()) {
			if(a[now] < a[i]) break;
			now = nxt[now];
		}
		nxt[i] = now;
	}

	for(int i = 0; i < a.size(); i++) {
		int now = i;
		while(now < a.size() and a[now]) {
			i64 S = now - i + 2, T = nxt[now] - i + 1;
			i64 len = (S + T) * (T - S + 1) >> 1;

			ans += len * a[now];
			now = nxt[now];
		}
	}

	printf("%lld\n", ans);
	return 0;
}
0