結果

問題 No.921 ずんだアロー
ユーザー polylogKpolylogK
提出日時 2019-09-17 22:10:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 767 bytes
コンパイル時間 1,489 ms
コンパイル使用メモリ 168,920 KB
実行使用メモリ 8,988 KB
最終ジャッジ日時 2023-10-13 08:37:37
合計ジャッジ時間 2,742 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,356 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 18 ms
8,212 KB
testcase_11 AC 18 ms
8,896 KB
testcase_12 AC 6 ms
4,356 KB
testcase_13 AC 13 ms
6,948 KB
testcase_14 AC 16 ms
7,692 KB
testcase_15 AC 9 ms
5,628 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 16 ms
7,724 KB
testcase_18 AC 19 ms
8,864 KB
testcase_19 AC 19 ms
8,812 KB
testcase_20 AC 18 ms
8,952 KB
testcase_21 AC 19 ms
8,988 KB
testcase_22 AC 19 ms
8,800 KB
testcase_23 AC 17 ms
8,784 KB
testcase_24 AC 19 ms
8,936 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() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);

	auto dp = make_v<int>(n + 1, 2);
	for(int i = 0; i < n; i++) {
		dp[i + 1][0] = std::max(dp[i][0], dp[i][1]);

		dp[i + 1][1] = dp[i][0] + 1;
		if(!i or a[i - 1] == a[i]) dp[i + 1][1] = std::max(dp[i + 1][1], dp[i][1] + 1);
	}
	printf("%d\n", std::max(dp[n][0], dp[n][1]));
	return 0;
}
0