結果

問題 No.962 LCPs
ユーザー polylogKpolylogK
提出日時 2019-12-22 11:30:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,403 bytes
コンパイル時間 1,631 ms
コンパイル使用メモリ 172,544 KB
実行使用メモリ 11,804 KB
最終ジャッジ日時 2023-10-12 02:22:43
合計ジャッジ時間 4,589 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 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 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 31 ms
11,804 KB
testcase_18 AC 18 ms
7,632 KB
testcase_19 AC 19 ms
7,364 KB
testcase_20 AC 14 ms
6,128 KB
testcase_21 AC 14 ms
6,084 KB
testcase_22 AC 12 ms
5,176 KB
testcase_23 AC 12 ms
5,308 KB
testcase_24 AC 12 ms
4,948 KB
testcase_25 AC 12 ms
5,180 KB
testcase_26 AC 11 ms
4,716 KB
testcase_27 AC 14 ms
5,484 KB
testcase_28 AC 10 ms
4,616 KB
testcase_29 AC 10 ms
4,356 KB
testcase_30 AC 12 ms
5,344 KB
testcase_31 AC 14 ms
5,940 KB
testcase_32 AC 9 ms
4,528 KB
testcase_33 AC 18 ms
7,316 KB
testcase_34 AC 11 ms
4,812 KB
testcase_35 AC 11 ms
4,732 KB
testcase_36 AC 12 ms
5,036 KB
testcase_37 AC 9 ms
4,348 KB
testcase_38 AC 9 ms
4,352 KB
testcase_39 AC 9 ms
4,352 KB
testcase_40 AC 9 ms
4,352 KB
testcase_41 AC 9 ms
4,348 KB
testcase_42 AC 10 ms
4,348 KB
testcase_43 AC 9 ms
4,352 KB
testcase_44 AC 9 ms
4,348 KB
testcase_45 AC 10 ms
4,348 KB
testcase_46 AC 9 ms
4,352 KB
testcase_47 AC 4 ms
4,352 KB
testcase_48 AC 4 ms
4,348 KB
testcase_49 AC 5 ms
4,348 KB
testcase_50 AC 5 ms
4,348 KB
testcase_51 AC 4 ms
4,356 KB
testcase_52 AC 4 ms
4,352 KB
testcase_53 AC 4 ms
4,348 KB
testcase_54 AC 4 ms
4,348 KB
testcase_55 AC 3 ms
4,348 KB
testcase_56 AC 6 ms
4,352 KB
testcase_57 AC 5 ms
4,348 KB
testcase_58 AC 5 ms
4,352 KB
testcase_59 AC 5 ms
4,352 KB
testcase_60 AC 5 ms
4,348 KB
testcase_61 AC 6 ms
4,352 KB
testcase_62 AC 6 ms
4,352 KB
testcase_63 AC 22 ms
8,848 KB
testcase_64 AC 6 ms
4,352 KB
testcase_65 AC 22 ms
8,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

#define NDEBUG

int main() {
	int n; scanf("%d", &n);
	std::vector<std::string> s(n);
	for(int i = 0; i < n; i++) 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;
	}

	#ifndef NDEBUG
	for(auto v: a) cout << v << " "; cout << endl;
	for(auto v: nxt) cout << v << " "; cout << endl;
	#endif

	for(int i = 0; i < a.size(); i++) {
		int now = i;
		while(now < a.size()) {
			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