結果

問題 No.1512 作文
ユーザー y61mpnly61mpnl
提出日時 2021-05-21 22:00:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 778 bytes
コンパイル時間 1,958 ms
コンパイル使用メモリ 201,764 KB
実行使用メモリ 12,224 KB
最終ジャッジ日時 2023-07-31 15:26:00
合計ジャッジ時間 3,726 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 25 ms
8,832 KB
testcase_05 AC 25 ms
8,564 KB
testcase_06 AC 24 ms
9,252 KB
testcase_07 AC 24 ms
8,756 KB
testcase_08 AC 24 ms
8,960 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 7 ms
4,376 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 7 ms
4,380 KB
testcase_19 AC 8 ms
4,380 KB
testcase_20 AC 8 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 5 ms
4,380 KB
testcase_36 AC 5 ms
4,380 KB
testcase_37 AC 4 ms
4,380 KB
testcase_38 AC 5 ms
4,380 KB
testcase_39 AC 5 ms
4,376 KB
testcase_40 AC 31 ms
11,868 KB
testcase_41 AC 32 ms
12,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(i,b,e) for(int i=b;i<e;i++)

int main(){
	int n;
	std::cin >> n;
	std::vector<std::string> ss;
	REP(i, 0, n){
		std::string s;
		std::cin >> s;
		bool ok = true;
		REP(j, 0, s.size()-1){
			if(s[j]>s[j+1]) ok = false;
		}
		if(ok) ss.push_back(s);
	}
	n = ss.size();

	int self[26] = {}, links[26][26] = {};
	REP(i, 0, n){
		int fr = ss[i].front()-'a', bk = ss[i].back()-'a';
		if(fr==bk){
			self[fr] += ss[i].size();
		}else{
			links[fr][bk] = std::max<int>(links[fr][bk], ss[i].size());
		}
	}

	int dist[26] = {};
	REP(i, 0, 26) REP(j, i+1, 26) {
		dist[j] = std::max(dist[j], dist[i] + self[i] + links[i][j]);
	}
	dist[25] += self[25];

	int ans = 0;
	REP(i, 0, 26) ans = std::max(ans, dist[i]);
	printf("%d\n", ans);
	return 0;
}

	
	
0