結果

問題 No.921 ずんだアロー
ユーザー wunderkammer2wunderkammer2
提出日時 2020-01-08 22:58:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,210 bytes
コンパイル時間 1,086 ms
コンパイル使用メモリ 101,804 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-05-02 13:09:20
合計ジャッジ時間 5,250 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

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())
	{
		reple(j, 0, i - 1)
		{
			dp[i + 1] = max(dp[i + 1], dp[j] + ps[i].second);
		}

		dp[i + 1] = max(dp[i + 1], dp[i]);
	}

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

	return 0;
}
0