結果

問題 No.962 LCPs
ユーザー polylogKpolylogK
提出日時 2019-12-22 11:29:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,471 bytes
コンパイル時間 1,619 ms
コンパイル使用メモリ 171,300 KB
実行使用メモリ 11,560 KB
最終ジャッジ日時 2023-10-12 02:21:48
合計ジャッジ時間 4,361 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,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,356 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 2 ms
4,356 KB
testcase_17 AC 20 ms
11,560 KB
testcase_18 AC 11 ms
7,400 KB
testcase_19 AC 11 ms
7,460 KB
testcase_20 AC 9 ms
5,944 KB
testcase_21 AC 9 ms
6,004 KB
testcase_22 AC 7 ms
5,360 KB
testcase_23 AC 7 ms
5,324 KB
testcase_24 AC 6 ms
4,880 KB
testcase_25 AC 6 ms
4,952 KB
testcase_26 AC 5 ms
4,672 KB
testcase_27 AC 8 ms
5,516 KB
testcase_28 AC 6 ms
4,564 KB
testcase_29 AC 5 ms
4,360 KB
testcase_30 AC 7 ms
5,324 KB
testcase_31 AC 8 ms
5,996 KB
testcase_32 AC 5 ms
4,380 KB
testcase_33 AC 11 ms
7,248 KB
testcase_34 AC 6 ms
4,708 KB
testcase_35 AC 6 ms
4,712 KB
testcase_36 AC 6 ms
5,004 KB
testcase_37 AC 5 ms
4,372 KB
testcase_38 AC 5 ms
4,352 KB
testcase_39 AC 5 ms
4,348 KB
testcase_40 AC 5 ms
4,348 KB
testcase_41 AC 6 ms
4,352 KB
testcase_42 AC 6 ms
4,352 KB
testcase_43 AC 6 ms
4,352 KB
testcase_44 AC 6 ms
4,352 KB
testcase_45 AC 5 ms
4,352 KB
testcase_46 AC 5 ms
4,348 KB
testcase_47 AC 2 ms
4,352 KB
testcase_48 AC 2 ms
4,352 KB
testcase_49 AC 3 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 2 ms
4,352 KB
testcase_52 AC 2 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,348 KB
testcase_56 AC 2 ms
4,372 KB
testcase_57 AC 3 ms
4,348 KB
testcase_58 AC 3 ms
4,352 KB
testcase_59 AC 3 ms
4,352 KB
testcase_60 AC 2 ms
4,356 KB
testcase_61 AC 2 ms
4,348 KB
testcase_62 AC 2 ms
4,352 KB
testcase_63 AC 13 ms
8,760 KB
testcase_64 AC 2 ms
4,348 KB
testcase_65 AC 14 ms
8,744 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() {
	std::ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n; cin >> 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