結果

問題 No.962 LCPs
ユーザー kotatsugamekotatsugame
提出日時 2019-12-25 01:57:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 696 bytes
コンパイル時間 1,306 ms
コンパイル使用メモリ 85,632 KB
実行使用メモリ 23,588 KB
最終ジャッジ日時 2023-10-24 03:48:43
合計ジャッジ時間 4,805 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
12,208 KB
testcase_01 AC 4 ms
12,208 KB
testcase_02 AC 4 ms
12,268 KB
testcase_03 AC 5 ms
12,236 KB
testcase_04 AC 4 ms
12,228 KB
testcase_05 AC 4 ms
12,220 KB
testcase_06 AC 5 ms
12,220 KB
testcase_07 AC 4 ms
12,228 KB
testcase_08 AC 4 ms
12,228 KB
testcase_09 AC 4 ms
12,228 KB
testcase_10 AC 4 ms
12,228 KB
testcase_11 AC 4 ms
12,220 KB
testcase_12 AC 4 ms
12,272 KB
testcase_13 AC 3 ms
12,272 KB
testcase_14 AC 4 ms
12,272 KB
testcase_15 AC 4 ms
12,272 KB
testcase_16 AC 4 ms
12,272 KB
testcase_17 AC 122 ms
23,588 KB
testcase_18 AC 62 ms
17,784 KB
testcase_19 AC 61 ms
17,784 KB
testcase_20 AC 41 ms
15,808 KB
testcase_21 AC 41 ms
15,808 KB
testcase_22 AC 33 ms
14,748 KB
testcase_23 AC 31 ms
14,748 KB
testcase_24 AC 27 ms
14,240 KB
testcase_25 AC 27 ms
14,240 KB
testcase_26 AC 24 ms
13,900 KB
testcase_27 AC 37 ms
15,248 KB
testcase_28 AC 24 ms
14,000 KB
testcase_29 AC 24 ms
13,732 KB
testcase_30 AC 35 ms
14,688 KB
testcase_31 AC 38 ms
15,808 KB
testcase_32 AC 20 ms
13,600 KB
testcase_33 AC 71 ms
17,504 KB
testcase_34 AC 29 ms
14,112 KB
testcase_35 AC 26 ms
13,928 KB
testcase_36 AC 30 ms
14,408 KB
testcase_37 AC 18 ms
13,460 KB
testcase_38 AC 18 ms
13,460 KB
testcase_39 AC 18 ms
13,456 KB
testcase_40 AC 18 ms
13,464 KB
testcase_41 AC 18 ms
13,456 KB
testcase_42 AC 18 ms
13,456 KB
testcase_43 AC 18 ms
13,460 KB
testcase_44 AC 18 ms
13,460 KB
testcase_45 AC 18 ms
13,464 KB
testcase_46 AC 18 ms
13,460 KB
testcase_47 AC 7 ms
12,400 KB
testcase_48 AC 7 ms
12,408 KB
testcase_49 AC 8 ms
12,400 KB
testcase_50 AC 8 ms
12,408 KB
testcase_51 AC 7 ms
12,396 KB
testcase_52 AC 6 ms
12,412 KB
testcase_53 AC 7 ms
12,472 KB
testcase_54 AC 7 ms
12,392 KB
testcase_55 AC 6 ms
12,396 KB
testcase_56 AC 8 ms
12,396 KB
testcase_57 AC 7 ms
12,540 KB
testcase_58 AC 8 ms
12,540 KB
testcase_59 AC 8 ms
12,540 KB
testcase_60 AC 9 ms
12,512 KB
testcase_61 AC 9 ms
12,512 KB
testcase_62 AC 8 ms
12,512 KB
testcase_63 AC 81 ms
19,492 KB
testcase_64 AC 9 ms
12,396 KB
testcase_65 AC 81 ms
19,492 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
using namespace std;
int N;
string s[2<<17];
int d[2<<17];
long ans;
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>s[i];
		ans+=s[i].size();
	}
	for(int i=0;i<N-1;i++)
	{
		while(d[i]<s[i].size()&&d[i]<s[i+1].size()&&s[i][d[i]]==s[i+1][d[i]])d[i]++;
	}
	vector<pair<int,int> >X;
	for(int i=0;i<N-1;i++)
	{
		X.push_back(make_pair(d[i],i+1));
	}
	sort(X.begin(),X.end());
	set<int>S;
	S.insert(0);
	S.insert(N);
	for(pair<int,int>p:X)
	{
		int id=p.second;
		set<int>::iterator it=S.lower_bound(id);
		long R=*it-id;
		it--;
		long L=id-*it;
		ans+=p.first*(R*L*(L+1)/2+L*R*(R+1)/2);
		S.insert(id);
	}
	cout<<ans<<endl;
}
0