結果

問題 No.1512 作文
ユーザー racsosaberacsosabe
提出日時 2021-05-21 22:52:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 1,891 ms
コンパイル使用メモリ 170,088 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-18 16:20:03
合計ジャッジ時間 3,522 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 26 ms
6,940 KB
testcase_05 AC 26 ms
6,940 KB
testcase_06 AC 25 ms
6,940 KB
testcase_07 AC 26 ms
6,944 KB
testcase_08 AC 26 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 6 ms
6,944 KB
testcase_15 AC 6 ms
6,944 KB
testcase_16 AC 6 ms
6,940 KB
testcase_17 AC 7 ms
6,940 KB
testcase_18 AC 6 ms
6,940 KB
testcase_19 AC 6 ms
6,940 KB
testcase_20 AC 6 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 3 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 3 ms
6,940 KB
testcase_36 AC 3 ms
6,940 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 3 ms
6,944 KB
testcase_39 AC 3 ms
6,940 KB
testcase_40 AC 31 ms
6,944 KB
testcase_41 AC 20 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace::std;

const int inf = 100000000 + 10;
const int N = 200000 + 5;
const int E = 26;

int n;
int L[N];
int R[N];
int len[N];
int maxi[E];
bool valid[N];

bool check(string s){
	for(int i = 1; i < s.size(); i++){
		if(s[i - 1] > s[i]) return false;
	}
	return true;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		len[i] = s.size();
		L[i] = s[0] - 'a';
		R[i] = s[len[i] - 1] - 'a';
		valid[i] = check(s);
	}
	vector<int> p(n);
	iota(p.begin(), p.end(), 0);
	sort(p.begin(), p.end(), [&] (int i, int j){
		if(R[i] == R[j]) return L[i] < L[j];
		return R[i] < R[j];
	});
	for(int i = 0; i < E; i++) maxi[i] = -inf;
	if(valid[p[0]]) maxi[R[p[0]]] = len[p[0]];
	for(int at = 1; at < n; at++){
		int i = p[at];
		if(valid[i]){
			int best = 0;
			for(int j = 0; j <= L[i]; j++){
				best = max(best, maxi[j]);
			}
			best += len[i];
			maxi[R[i]] = max(maxi[R[i]], best);
		}
	}
	cout << max(0, *max_element(maxi, maxi + E)) << endl;
	return 0;
}
0