結果

問題 No.921 ずんだアロー
ユーザー polylogKpolylogK
提出日時 2019-09-12 18:12:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,044 bytes
コンパイル時間 1,677 ms
コンパイル使用メモリ 172,136 KB
実行使用メモリ 9,672 KB
最終ジャッジ日時 2023-10-13 08:37:15
合計ジャッジ時間 3,079 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 18 ms
9,320 KB
testcase_11 AC 21 ms
9,460 KB
testcase_12 AC 6 ms
4,440 KB
testcase_13 AC 15 ms
7,848 KB
testcase_14 AC 17 ms
8,268 KB
testcase_15 AC 10 ms
6,112 KB
testcase_16 AC 3 ms
4,352 KB
testcase_17 AC 17 ms
8,416 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 20 ms
9,672 KB
testcase_24 AC 12 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	// input
	int n; scanf("%d", &n);
	assert(1 <= n and n <= (int)1e5);

	std::vector<int> a(n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &a[i]);

		assert(1 <= a[i] and a[i] <= (int)1e5);
	}

	// solve
	std::vector<std::pair<int, int>> vec;
	for(int i = 0; i < n; i++) {
		if(vec.empty() or vec.back().first != a[i]) vec.push_back({a[i], 1});
		else vec.back().second++;
	}

	auto dp = make_v<int>(vec.size() + 1, 2);
	for(int i = 0; i < vec.size(); i++) {
		dp[i + 1][0] = std::max({dp[i + 1][0], dp[i][1], dp[i][0]});
		dp[i + 1][1] = std::max({dp[i + 1][1], dp[i][0] + vec[i].second});
	}
	printf("%d\n", std::max(dp.back()[0], dp.back()[1]));
	return 0;
}
0