結果

問題 No.962 LCPs
ユーザー chocoruskchocorusk
提出日時 2019-12-24 23:23:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,220 bytes
コンパイル時間 1,900 ms
コンパイル使用メモリ 123,520 KB
実行使用メモリ 20,572 KB
最終ジャッジ日時 2023-10-23 22:12:27
合計ジャッジ時間 4,909 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,868 KB
testcase_01 AC 5 ms
9,868 KB
testcase_02 AC 6 ms
9,924 KB
testcase_03 AC 5 ms
9,896 KB
testcase_04 AC 5 ms
9,888 KB
testcase_05 AC 5 ms
9,880 KB
testcase_06 AC 5 ms
9,880 KB
testcase_07 AC 6 ms
9,888 KB
testcase_08 AC 5 ms
9,888 KB
testcase_09 AC 5 ms
9,888 KB
testcase_10 AC 5 ms
9,888 KB
testcase_11 AC 5 ms
9,880 KB
testcase_12 AC 5 ms
9,928 KB
testcase_13 AC 5 ms
9,928 KB
testcase_14 AC 5 ms
9,928 KB
testcase_15 AC 5 ms
9,928 KB
testcase_16 AC 5 ms
9,928 KB
testcase_17 AC 124 ms
20,572 KB
testcase_18 AC 61 ms
15,044 KB
testcase_19 AC 61 ms
15,044 KB
testcase_20 AC 42 ms
13,196 KB
testcase_21 AC 42 ms
13,196 KB
testcase_22 AC 33 ms
12,212 KB
testcase_23 AC 33 ms
12,212 KB
testcase_24 AC 29 ms
11,744 KB
testcase_25 AC 29 ms
11,744 KB
testcase_26 AC 25 ms
11,432 KB
testcase_27 AC 37 ms
12,676 KB
testcase_28 AC 24 ms
11,524 KB
testcase_29 AC 25 ms
11,276 KB
testcase_30 AC 35 ms
12,148 KB
testcase_31 AC 39 ms
13,196 KB
testcase_32 AC 20 ms
11,156 KB
testcase_33 AC 70 ms
14,780 KB
testcase_34 AC 29 ms
11,620 KB
testcase_35 AC 26 ms
11,456 KB
testcase_36 AC 29 ms
11,900 KB
testcase_37 AC 19 ms
11,044 KB
testcase_38 AC 19 ms
11,044 KB
testcase_39 AC 18 ms
11,040 KB
testcase_40 AC 19 ms
11,048 KB
testcase_41 AC 19 ms
11,040 KB
testcase_42 AC 19 ms
11,040 KB
testcase_43 AC 18 ms
11,044 KB
testcase_44 AC 19 ms
11,044 KB
testcase_45 AC 19 ms
11,048 KB
testcase_46 AC 19 ms
11,044 KB
testcase_47 AC 8 ms
10,056 KB
testcase_48 AC 8 ms
10,064 KB
testcase_49 AC 9 ms
10,056 KB
testcase_50 AC 9 ms
10,064 KB
testcase_51 AC 9 ms
10,056 KB
testcase_52 AC 8 ms
10,068 KB
testcase_53 AC 8 ms
10,128 KB
testcase_54 AC 8 ms
10,048 KB
testcase_55 AC 7 ms
10,052 KB
testcase_56 AC 9 ms
10,056 KB
testcase_57 AC 9 ms
10,196 KB
testcase_58 AC 9 ms
10,196 KB
testcase_59 AC 9 ms
10,196 KB
testcase_60 AC 10 ms
10,168 KB
testcase_61 AC 10 ms
10,168 KB
testcase_62 AC 10 ms
10,168 KB
testcase_63 AC 82 ms
16,628 KB
testcase_64 AC 9 ms
10,056 KB
testcase_65 AC 83 ms
16,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	cin>>n;
	string s[200020];
	ll ans=0;
	for(int i=0; i<n; i++){
		cin>>s[i];
		ans+=s[i].size();
	}
	int l[200020];
	vector<P> v;
	for(int i=0; i<n-1; i++){
		bool dame=0;
		for(int j=0; j<min(s[i].size(), s[i+1].size()); j++){
			if(s[i][j]!=s[i+1][j]){
				dame=1;
				l[i]=j;
				break;
			}
		}
		if(!dame){
			l[i]=min(s[i].size(), s[i+1].size());
		}
		v.push_back({l[i], i});
	}
	set<int> st;
	st.insert(-1);
	st.insert(n-1);
	sort(v.begin(), v.end());
	for(auto p:v){
		int k=p.second;
		ll x=p.first;
		auto itr=st.lower_bound(k);
		int q=*itr;
		itr--;
		int r=*itr;
		st.insert(k);
		ans+=x*(q-k)*(k-r)*(q-r+2)/2;
	}
	cout<<ans<<endl;
	return 0;
}
0