結果

問題 No.37 遊園地のアトラクション
ユーザー ramia777ramia777
提出日時 2022-05-23 01:37:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 991 ms / 5,000 ms
コード長 2,605 bytes
コンパイル時間 737 ms
コンパイル使用メモリ 94,684 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 17:24:57
合計ジャッジ時間 2,989 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 4 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 26 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 15 ms
4,348 KB
testcase_11 AC 17 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 7 ms
4,348 KB
testcase_17 AC 7 ms
4,348 KB
testcase_18 AC 19 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 5 ms
4,348 KB
testcase_21 AC 4 ms
4,348 KB
testcase_22 AC 991 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 1 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//Yukicoder
//Q37 遊園地のアトラクション
//




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

//#include "stdafx.h"
#include <iostream>
#include <vector>
#include <list>//list
#include <set> //tree
#include <map> //連想配列
#include <unordered_set> //hash
#include <unordered_map> //hash
#include <algorithm>
#include <iomanip>

using namespace std;
typedef unsigned long long ULL;
typedef signed long long SLL;


#define START (0)
#define RIGHT (1)
#define UP    (2)
#define LEFT  (3)
#define DOWN  (4)

#define DATA_MAX (1000000)
#define FMAX(a,b)  ((a)>(b)?(a):(b))
#define FMIX(a,b)  ((a)<(b)?(a):(b))


vector <vector <SLL>> memo2;
vector<SLL> memo1;


SLL N, D, H ,A, B, T;


typedef struct CAR {
	int c;
	int v;
}CAR;

CAR car[20];


//昇順
int compare(const CAR * a, const CAR *b)
{
	if (a->c > b->c)
		return (1);
	else if (a->c < b->c)
		return (-1);
	return (0);
}


// N種類までのアトラクションに乗れた場合に、T時間の時点での最大満足度を保存してく
// dp[N][T]

int dp[20][10100];


void debug_print( void )
{
	cout << "---" << endl;
	for (int i = 0; i < N; i++)
	{
		for (int j = 1; j <= T; j++)
			cout << dp[i][j] << ",";
		cout << endl;
	}
}

int main()
{

	//float min = INFINITY;

	cin >> T;
	cin >> N;


	for (int  i = 0; i < N; i++)
	{
		cin >> car[i].c;	
	}
	for (int i = 0; i < N; i++)
	{
		cin >> car[i].v;
	}



	//アトラクションの時間の昇順にソート
	qsort(car, N, sizeof(CAR), (int(*)(const void*, const void*))compare);

	/*
	for (int i = 0; i < N; i++)
		cout << "c=" << car[i].c << ",v=" << car[i].v << endl;
	*/

	int v = car[0].v;
	int first = 1;

	//最初の1行
	for (int t = 1; t <= T; t++)
	{
		if (t >= car[0].c)
		{
			if (((t % car[0].c) == 0) && (first==0))
			{
				car[0].v >>= 1;
				v += car[0].v;
			}

			dp[0][t] = v;
			first = 0;
		}
	}


	



	//2行目以降
	for (int n = 1; n < N; n++)
	{
		for (int t = 1; t <= T; t++)
		{
			//debug_print();

			if (t >= car[n].c)
			{
				int curr=0;
				int v0 = car[n].v;
				int vv = car[n].v;
				int mmax = 0;
				int m = 1;

				// 1つ前の満足度と今回のものを足した時の満足度(1回以上)を比較
				do {
					
					curr = dp[n - 1][t - car[n].c*m] + v0;
					if (mmax < curr)
						mmax = curr;
					m++;
					
					vv /= 2;
					v0 += vv;

				} while (t > (car[n].c * m) );



				dp[n][t] = (mmax > dp[n - 1][t]) ? mmax : dp[n - 1][t];

			}
			else
			{
				
				dp[n][t] = dp[n - 1][t];
			}
		}
	}

	cout << dp[N-1][T] << endl;

	//getchar();
	return 0; //end
}

0