結果

問題 No.1512 作文
ユーザー takumattakumat
提出日時 2021-05-21 22:07:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,710 bytes
コンパイル時間 4,932 ms
コンパイル使用メモリ 257,880 KB
実行使用メモリ 41,004 KB
最終ジャッジ日時 2024-04-18 15:37:06
合計ジャッジ時間 6,573 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007LL;//998244353LL;
static const LLONG INF_NUM = MOD_NUM * 20LL;
template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}
template <class _T> static _T tp_pow(int x, int exp)
{
	_T ans = 1;
	_T base = x;
	while (exp > 0) {
		if (exp & 1) {
			ans = (ans * base);
		}
		base = (base * base);
		exp >>= 1;
	}
	return ans;
}

static void task();

int main()
{
	task();
	fflush(stdout);
	return 0;
}

static void task()
{
	int N;
	get(N);

	std::vector<std::pair<int, int>> code(N, std::pair<int, int>{MOD_NUM, MOD_NUM});
	std::vector<std::string> si(N);
	for (int i = 0; i < N; i++) {
		get(si[i]);

		bool asc = true;
		int len = si[i].length();
		int first = si[i][0], end = si[i][len - 1];
		for (int j = 1; j < len; j++) {
			if (si[i][j] < si[i][j - 1]) {
				asc = false;
				break;
			}
		}

		if (asc) {
			code[i].first = first - 'a' + 1;
			code[i].second = end - 'a' + 1;
		}
	}
	std::vector<std::vector<int>> dp(N + 1, std::vector<int>(27, 0));
	for (int c = 0; c < 26; c++) {
		for (int i = 0; i < N; i++) {
			dp[i + 1][c + 1] = std::max({ dp[i][c], dp[i][c + 1], dp[i + 1][c] });
			if (code[i].second == c + 1) {
				if (dp[i + 1][c + 1] < dp[i][code[i].first] + si[i].length()) {
					dp[i + 1][c + 1] = dp[i][code[i].first] + si[i].length();
				}
			}
		}
	}
	printf("%d\n", dp[N][26]);
}
0