結果

問題 No.921 ずんだアロー
ユーザー wunderkammer2wunderkammer2
提出日時 2020-01-08 23:00:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,183 bytes
コンパイル時間 1,074 ms
コンパイル使用メモリ 101,052 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-02 13:09:26
合計ジャッジ時間 2,295 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 31 ms
5,804 KB
testcase_11 AC 33 ms
5,964 KB
testcase_12 AC 9 ms
5,376 KB
testcase_13 AC 24 ms
5,720 KB
testcase_14 AC 27 ms
5,768 KB
testcase_15 AC 16 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 28 ms
5,768 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 33 ms
6,100 KB
testcase_24 AC 31 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

typedef pair<ll, ll> P;

int main()
{	
	int N;
	cin >> N;

	vector<int> as(N);
	rep(i, N)
	{
		cin >> as[i];
	}

	vector<P> ps;
	{
		ll prev = as[0];
		ll count = 1;

		repl(i, 1, N)
		{
			if (as[i] != prev)
			{
				ps.emplace_back(prev, count);
				prev = as[i];
				count = 0;
			}

			++count;
		}

		ps.emplace_back(prev, count);
	}

	//dp[i] := ps[i - 1]までの餅のいくつかをずんだ餅に変えた時の、ずんだ餅の個数の最大値
	vector<ll> dp(ps.size() + 1, -1);
	dp[0] = 0;
	dp[1] = ps[0].second;

	repl(i, 1, ps.size())
	{
		dp[i + 1] = max(dp[i + 1], dp[i - 1] + ps[i].second);
		dp[i + 1] = max(dp[i + 1], dp[i]);
	}

	cout << dp[dp.size() - 1] << endl;

	return 0;
}
0