結果

問題 No.45 回転寿司
ユーザー ramia777ramia777
提出日時 2022-06-07 01:06:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,559 bytes
コンパイル時間 1,004 ms
コンパイル使用メモリ 95,972 KB
実行使用メモリ 7,664 KB
最終ジャッジ日時 2023-10-21 03:44:17
合計ジャッジ時間 2,036 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,444 KB
testcase_01 AC 2 ms
6,444 KB
testcase_02 AC 3 ms
6,988 KB
testcase_03 AC 3 ms
7,276 KB
testcase_04 AC 2 ms
6,444 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
6,444 KB
testcase_07 AC 3 ms
6,948 KB
testcase_08 AC 3 ms
6,444 KB
testcase_09 AC 3 ms
7,116 KB
testcase_10 AC 2 ms
6,444 KB
testcase_11 AC 3 ms
6,444 KB
testcase_12 AC 4 ms
7,068 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
6,444 KB
testcase_16 AC 3 ms
6,444 KB
testcase_17 AC 3 ms
6,444 KB
testcase_18 AC 3 ms
6,444 KB
testcase_19 AC 4 ms
6,616 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 3 ms
6,444 KB
testcase_27 AC 3 ms
6,624 KB
testcase_28 AC 3 ms
6,444 KB
testcase_29 AC 4 ms
6,444 KB
testcase_30 AC 3 ms
6,484 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 4 ms
7,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicodr
// No.45



//二次元可変配列
//vector <vector <int>> mass;
//vector <vector <int>> memo;
//vector <int> memo;


//#include "stdafx.h"
#include <iostream>
#include <vector>
#include <list>//list
#include <queue> //queue
#include <set> //連想コンテナ(要素が自動でソートされる)、要素1つ(Key)、keyの重複ない、O(logN)
#include <map> //連想コンテナ(要素が自動でソートされる)、要素2つ(Key,data)、keyの重複ない、dataは重複あり、O(logN)
#include <unordered_set> //hash、O(1)
#include <unordered_map> //hash、O(1)
#include <algorithm>
#include <iomanip>
#include <cstring>
//#include <bits/stdc++.h>

using namespace std;

#define FOR(x,to) for(x=0;x<to;x++)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define FMAX(a,b)  ((a)>(b)?(a):(b))
#define FMIN(a,b)  ((a)<(b)?(a):(b))
#define FCEIL(a,b)  ((a)+(b)-1)/(b)

typedef unsigned long long ULL;
typedef signed long long SLL;


queue<int> _queue;



int N;
int dp[1005][1005];
int V[1005];
int main()
{

	cin >> N;

	for (int i = 1; i <= N; i++)
	{
		scanf("%d", &V[i]);
	}

	for (int i = 1; i <= N; i++)
	{
		dp[1][i] = V[1];
	}

	dp[2][1] = dp[1][1];
	for (int i = 1; i <= N; i++)
	{
		if (i >= 2)
		{
			dp[2][i] = FMAX(dp[1][i],V[i]);
		}
	}


	for (int n = 3; n <= N; n++)
	{
		for (int i = 1; i <= N; i++)
		{
			if (i>=n)
			{
				dp[n][i] = FMAX(dp[n - 1][i - 1],dp[n-1][i-2]+V[i]);
			}
			else
			{
				dp[n][i] = dp[n - 1][i];
			}
		}
	}

	cout << dp[N][N] << endl;

	return 0;

}

0