結果

問題 No.921 ずんだアロー
コンテスト
ユーザー fura
提出日時 2020-04-30 02:40:31
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 601 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,216 ms
コンパイル使用メモリ 213,928 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2026-06-09 20:38:25
合計ジャッジ時間 3,063 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

template<class T>
vector<pair<T,int>> run_length_encoding(const vector<T>& a){
	vector<pair<T,int>> res;
	int n=a.size(),pre=0;
	rep(i,n) if(i==n-1 || a[i]!=a[i+1]) res.emplace_back(a[i],i-pre+1), pre=i+1;
	return res;
}

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	auto rle=run_length_encoding(a);
	int m=rle.size();

	vector<int> dp(m+1);
	dp[1]=rle[0].second;
	for(int i=1;i<m;i++){
		dp[i+1]=max(dp[i],dp[i-1]+rle[i].second);
	}
	printf("%d\n",dp[m]);

	return 0;
}
0