結果

問題 No.1512 作文
ユーザー maimaicorgimaimaicorgi
提出日時 2022-09-27 14:31:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,763 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 144,596 KB
実行使用メモリ 35,920 KB
最終ジャッジ日時 2023-08-24 03:51:59
合計ジャッジ時間 6,861 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <ios>
#include <iomanip>
#include <queue>
#include <numeric>
#include <map>
#include <set>
#include <sstream>
#include <bitset>
#include <climits>
#include <stack>
#include <regex>
#include <functional>
#include <random>
#ifdef _WIN64
#  include <atcoder/all>
#endif
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#  define __builtin_popcountl __popcnt64
#endif

using namespace std;

#define ll long long
#define rep(i, init, n) for(ll i = init; i < (ll)n; i++)
#define rrep(i, init, n) for(ll i = init; i >= (ll)n; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x.size())
#define Out(x) cout << x << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define Ans cout << ans << endl
#define PI 3.14159265358979
#define MOD 998244353

const int inf32 = INT_MAX / 2;
const ll inf64 = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

// -------------------------------------------------------------------------------------------------

int main()
{
	int n; cin >> n;
	vector<string> s(n + 1);
	rep(i, 1, n + 1) cin >> s[i];

	vector dp(n + 1, vector<int>(26, -inf32));
	dp[0][0] = 0;

	rep(i, 1, n + 1)rep(j, 0, 26)
	{
		chmax(dp[i][j], dp[i - 1][j]);

		string str = s[i];
		sort(all(str));
		if (s[i] != str) continue;

		if (j <= (s[i][0] - 'a')) chmax(dp[i][s[i].back() - 'a'], dp[i - 1][j] + (int)s[i].length());
	}

	int ans = -inf32;
	rep(i, 0, 26) chmax(ans, dp[n][i]);

	Ans;

	return 0;
}
0