結果

問題 No.1512 作文
ユーザー y61mpnly61mpnl
提出日時 2021-05-21 21:54:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 755 bytes
コンパイル時間 1,997 ms
コンパイル使用メモリ 199,292 KB
実行使用メモリ 12,324 KB
最終ジャッジ日時 2024-04-18 15:12:53
合計ジャッジ時間 3,353 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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]);
	}

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

	
	
0