結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,356 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 31 ms
11,740 KB
testcase_18 AC 19 ms
7,536 KB
testcase_19 AC 18 ms
7,512 KB
testcase_20 AC 15 ms
6,056 KB
testcase_21 AC 15 ms
6,016 KB
testcase_22 AC 12 ms
5,440 KB
testcase_23 AC 13 ms
5,232 KB
testcase_24 AC 12 ms
4,936 KB
testcase_25 AC 11 ms
4,912 KB
testcase_26 AC 11 ms
4,560 KB
testcase_27 AC 14 ms
5,496 KB
testcase_28 AC 10 ms
4,704 KB
testcase_29 AC 10 ms
4,384 KB
testcase_30 AC 12 ms
5,120 KB
testcase_31 AC 15 ms
5,884 KB
testcase_32 AC 10 ms
4,352 KB
testcase_33 AC 18 ms
7,268 KB
testcase_34 AC 11 ms
4,656 KB
testcase_35 AC 11 ms
4,684 KB
testcase_36 AC 12 ms
4,952 KB
testcase_37 AC 9 ms
4,400 KB
testcase_38 AC 10 ms
4,348 KB
testcase_39 AC 10 ms
4,348 KB
testcase_40 AC 9 ms
4,352 KB
testcase_41 AC 10 ms
4,352 KB
testcase_42 AC 9 ms
4,348 KB
testcase_43 AC 9 ms
4,352 KB
testcase_44 AC 9 ms
4,352 KB
testcase_45 AC 10 ms
4,364 KB
testcase_46 AC 9 ms
4,348 KB
testcase_47 AC 4 ms
4,352 KB
testcase_48 AC 4 ms
4,352 KB
testcase_49 AC 5 ms
4,348 KB
testcase_50 AC 5 ms
4,348 KB
testcase_51 AC 5 ms
4,348 KB
testcase_52 AC 4 ms
4,352 KB
testcase_53 AC 5 ms
4,348 KB
testcase_54 AC 4 ms
4,348 KB
testcase_55 AC 4 ms
4,352 KB
testcase_56 AC 5 ms
4,348 KB
testcase_57 AC 5 ms
4,348 KB
testcase_58 AC 5 ms
4,348 KB
testcase_59 AC 5 ms
4,352 KB
testcase_60 AC 6 ms
4,348 KB
testcase_61 AC 6 ms
4,352 KB
testcase_62 AC 6 ms
4,348 KB
testcase_63 AC 21 ms
8,848 KB
testcase_64 AC 5 ms
4,348 KB
testcase_65 AC 21 ms
8,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
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