結果

問題 No.921 ずんだアロー
ユーザー chocopuuchocopuu
提出日時 2019-11-08 21:30:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 998 bytes
コンパイル時間 1,671 ms
コンパイル使用メモリ 166,408 KB
実行使用メモリ 7,244 KB
最終ジャッジ日時 2023-10-13 03:32:49
合計ジャッジ時間 3,194 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,476 KB
testcase_01 AC 4 ms
6,528 KB
testcase_02 AC 4 ms
6,564 KB
testcase_03 AC 4 ms
6,452 KB
testcase_04 AC 4 ms
6,676 KB
testcase_05 AC 4 ms
6,480 KB
testcase_06 AC 4 ms
6,540 KB
testcase_07 AC 3 ms
6,448 KB
testcase_08 AC 4 ms
6,468 KB
testcase_09 AC 4 ms
6,468 KB
testcase_10 AC 28 ms
6,740 KB
testcase_11 AC 29 ms
7,032 KB
testcase_12 AC 10 ms
6,444 KB
testcase_13 AC 23 ms
6,804 KB
testcase_14 AC 25 ms
6,856 KB
testcase_15 AC 16 ms
6,616 KB
testcase_16 AC 5 ms
6,496 KB
testcase_17 AC 25 ms
6,668 KB
testcase_18 AC 31 ms
7,144 KB
testcase_19 AC 31 ms
7,068 KB
testcase_20 AC 31 ms
7,012 KB
testcase_21 AC 30 ms
7,116 KB
testcase_22 AC 31 ms
7,140 KB
testcase_23 AC 30 ms
7,072 KB
testcase_24 AC 31 ms
7,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll = long long;
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
constexpr long long INF = 1e18, MOD = 1000000007;

int dp[200020][2];

signed main(){
	int N;
	cin>>N;
	vector<int>a(N);
	REP(i,N){
		cin>>a[i];
	}
	REP(i,200020)REP(j,2)dp[i][j]=-1;
	dp[0][0] = 0;
	dp[0][1] = 1;
	FOR(i,0,N-1){
		if(a[i+1]==a[i]){
			CHMAX(dp[i+1][1],dp[i][1]+1);
			CHMAX(dp[i+1][0],dp[i][0]);
			CHMAX(dp[i+1][1],dp[i][0]+1);
		}else{
			CHMAX(dp[i+1][1],dp[i][0]+1);
			CHMAX(dp[i+1][0],dp[i][1]);
		}
	}
	cout<<max(dp[N-1][0],dp[N-1][1])<<endl;
}
0