結果

問題 No.962 LCPs
ユーザー square1001square1001
提出日時 2020-01-11 21:07:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 905 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 85,516 KB
実行使用メモリ 20,308 KB
最終ジャッジ日時 2023-08-17 03:45:34
合計ジャッジ時間 4,794 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 83 ms
20,308 KB
testcase_18 AC 44 ms
11,660 KB
testcase_19 AC 44 ms
11,668 KB
testcase_20 AC 31 ms
8,804 KB
testcase_21 AC 31 ms
8,800 KB
testcase_22 AC 24 ms
7,196 KB
testcase_23 AC 24 ms
7,372 KB
testcase_24 AC 21 ms
6,424 KB
testcase_25 AC 21 ms
6,424 KB
testcase_26 AC 19 ms
6,224 KB
testcase_27 AC 28 ms
7,804 KB
testcase_28 AC 19 ms
6,300 KB
testcase_29 AC 17 ms
5,728 KB
testcase_30 AC 24 ms
7,232 KB
testcase_31 AC 31 ms
8,860 KB
testcase_32 AC 16 ms
5,508 KB
testcase_33 AC 43 ms
11,276 KB
testcase_34 AC 20 ms
6,216 KB
testcase_35 AC 19 ms
5,984 KB
testcase_36 AC 22 ms
6,664 KB
testcase_37 AC 15 ms
4,980 KB
testcase_38 AC 15 ms
5,172 KB
testcase_39 AC 15 ms
5,012 KB
testcase_40 AC 15 ms
4,996 KB
testcase_41 AC 15 ms
4,880 KB
testcase_42 AC 15 ms
4,988 KB
testcase_43 AC 15 ms
4,920 KB
testcase_44 AC 15 ms
5,164 KB
testcase_45 AC 15 ms
4,944 KB
testcase_46 AC 15 ms
4,912 KB
testcase_47 AC 5 ms
4,376 KB
testcase_48 AC 4 ms
4,380 KB
testcase_49 AC 4 ms
4,380 KB
testcase_50 AC 5 ms
4,380 KB
testcase_51 AC 5 ms
4,380 KB
testcase_52 AC 4 ms
4,380 KB
testcase_53 AC 5 ms
4,376 KB
testcase_54 AC 4 ms
4,376 KB
testcase_55 AC 3 ms
4,380 KB
testcase_56 AC 5 ms
4,380 KB
testcase_57 AC 4 ms
4,380 KB
testcase_58 AC 5 ms
4,380 KB
testcase_59 AC 5 ms
4,380 KB
testcase_60 AC 5 ms
4,500 KB
testcase_61 AC 5 ms
4,384 KB
testcase_62 AC 6 ms
4,380 KB
testcase_63 AC 57 ms
14,252 KB
testcase_64 AC 5 ms
4,380 KB
testcase_65 AC 57 ms
14,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<string> S(N);
	for (int i = 0; i < N; ++i) {
		cin >> S[i];
	}
	vector<int> A(N - 1);
	for (int i = 1; i < N; ++i) {
		int lcp = 0;
		for (int j = 0; j < S[i - 1].size() && j < S[i].size(); ++j) {
			if (S[i][j] != S[i - 1][j]) break;
			++lcp;
		}
		A[i - 1] = lcp;
	}
	vector<int> p(N - 1);
	for (int i = 0; i < N - 1; ++i) {
		p[i] = i;
	}
	sort(p.begin(), p.end(), [&](int i, int j) { return A[i] < A[j]; });
	set<int> s;
	s.insert(-1);
	s.insert(N - 1);
	long long ans = 0;
	for (int i = 0; i < N - 1; ++i) {
		set<int>::iterator it = s.lower_bound(p[i]);
		int r = *it, l = *(--it);
		ans += 1LL * (A[p[i]]) * (r - p[i]) * (p[i] - l) * (r - l + 2) / 2;
		s.insert(p[i]);
	}
	for (int i = 0; i < N; ++i) {
		ans += S[i].size();
	}
	cout << ans << endl;
	return 0;
}
0