結果

問題 No.1512 作文
ユーザー racsosaberacsosabe
提出日時 2021-05-21 22:36:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 915 bytes
コンパイル時間 1,862 ms
コンパイル使用メモリ 165,532 KB
実行使用メモリ 7,116 KB
最終ジャッジ日時 2024-04-18 16:06:48
合計ジャッジ時間 3,100 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 6 ms
6,940 KB
testcase_10 AC 6 ms
6,940 KB
testcase_11 AC 5 ms
6,940 KB
testcase_12 AC 6 ms
6,940 KB
testcase_13 AC 6 ms
6,940 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 3 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 WA -
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 2 ms
6,940 KB
testcase_31 AC 3 ms
6,944 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 2 ms
6,944 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 6 ms
6,940 KB
testcase_36 AC 7 ms
6,940 KB
testcase_37 AC 4 ms
6,944 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 28 ms
7,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

int n;
int L[N];
int R[N];
int len[N];
int maxi[E];
int memo[N];
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(){
	cin >> n;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		L[i] = s[0] - 'a';
		R[i] = s[s.size() - 1] - 'a';
		len[i] = s.size();
		valid[i] = check(s);
	}
	for(int i = 0; i < E; i++) maxi[i] = -inf;
	memo[0] = valid[0] ? len[0] : -inf;
	if(valid[0]) maxi[R[0]] = len[0];
	for(int i = 1; i < n; i++){
		if(valid[i]){
			int best = len[i];
			for(int j = 0; j <= L[i]; j++){
				best = max(best, len[i] + maxi[j]);
			}
			memo[i] = best;
			maxi[R[i]] = max(maxi[R[i]], best);
		}
		else memo[i] = -inf;
	}
	printf("%d\n", max(0, *max_element(maxi, maxi + E)));
	return 0;
}
0