結果

問題 No.1512 作文
ユーザー racsosaberacsosabe
提出日時 2021-05-21 22:51:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,023 bytes
コンパイル時間 1,735 ms
コンパイル使用メモリ 170,612 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-18 16:18:13
合計ジャッジ時間 2,905 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 WA -
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,944 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 1 ms
6,944 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 3 ms
6,940 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 3 ms
6,940 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 23 ms
6,944 KB
testcase_41 AC 15 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){
		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