結果

問題 No.921 ずんだアロー
ユーザー mmn15277198mmn15277198
提出日時 2021-01-27 20:31:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 653 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 168,388 KB
実行使用メモリ 8,964 KB
最終ジャッジ日時 2023-09-07 03:34:49
合計ジャッジ時間 4,335 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 32 ms
8,352 KB
testcase_11 AC 35 ms
8,796 KB
testcase_12 AC 9 ms
4,384 KB
testcase_13 AC 26 ms
6,984 KB
testcase_14 AC 28 ms
7,868 KB
testcase_15 AC 18 ms
5,624 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 30 ms
7,772 KB
testcase_18 AC 36 ms
8,844 KB
testcase_19 AC 36 ms
8,932 KB
testcase_20 AC 36 ms
8,964 KB
testcase_21 AC 37 ms
8,840 KB
testcase_22 AC 35 ms
8,828 KB
testcase_23 AC 36 ms
8,896 KB
testcase_24 AC 36 ms
8,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

const ld pi = 3.14159265358979;
const int mod = 1000000007;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	vector<vector<int>> dp(n + 10 , vector<int>(2 , 0));
	dp[0][0] = 0;
	dp[0][1] = 1;
	for(int i = 1; i < n; i++){
		if(a[i] != a[i - 1]){
			dp[i][0] = max(dp[i - 1][1] , dp[i - 1][0]);
			dp[i][1] = dp[i - 1][0] + 1;
		}else{
			dp[i][1] = max(dp[i - 1][1] + 1 , dp[i - 1][0] + 1);
			dp[i][0] = max(dp[i - 1][0] , dp[i - 1][1]);
		}
	}
	cout << max(dp[n - 1][0] , dp[n - 1][1]) << endl;
	return 0;
}
0