제출 #370863

#제출 시각아이디문제언어결과실행 시간메모리
370863MilosMilutinovicJelly Flavours (IOI20_jelly)C++14
45 / 100
1354 ms408712 KiB
#include "jelly.h"
#include <bits/stdc++.h>

using namespace std;

void ckmax(int& a, int b) {a = max(a, b);}
void ckmin(int& a, int b) {a = min(a, b);}

const int N = 205;

int dp[N][501][501];

int find_maximum_unique(int x, int y, vector<int> a, vector<int> b) {
	int n = (int) a.size();
	if (y == 0) {
		sort(a.begin(), a.end());
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (x >= a[i]) {
				x -= a[i];
				ans++;
			} else {
				break;
			}
		}
		return ans;
	}
	bool same = true;
	for (int i = 1; i < n; i++) {
		if (b[i] != b[i - 1]) {
			same = false;
		}
	}
	if (same) {
		int ans = 0;
		sort(a.begin(), a.end());
		for (int i = 0; i < n; i++) {
			if (x >= a[i]) {
				x -= a[i];
				ans++;
			} else {
				break;
			}
		}
		int left = n - ans;
		ans += min(left, (b[0] == 0 ? left : y / b[0]));
		return ans;
	}
	for (int i = 0; i < n; i++) {
		for (int xx = 0; xx <= x; xx++) {
			for (int yy = 0; yy <= y; yy++) {
				dp[i][xx][yy] = 0;
			}
		}
	}
	if (x >= a[0]) dp[0][x - a[0]][y] = 1;
	if (y >= b[0]) dp[0][x][y - b[0]] = 1;
	for (int i = 1; i < n; i++) {
		//if (x >= a[0]) ckmax(dp[i][x - a[i]][y], 1);
		//if (y >= b[0]) ckmax(dp[i][x][y - b[i]], 1);
		for (int j = i - 1; j < i; j++) {
			for (int xx = 0; xx <= x; xx++) {
				for (int yy = 0; yy <= y; yy++) {
					if (xx >= a[i]) {
						ckmax(dp[i][xx - a[i]][yy], dp[j][xx][yy] + 1);
					}
					if (yy >= b[i]) {
						ckmax(dp[i][xx][yy - b[i]], dp[j][xx][yy] + 1);
					}
					ckmax(dp[i][xx][yy], dp[j][xx][yy]);
				}
			}
		}
	}
	int ans = 0;
	for (int i = n - 1; i < n; i++) {
		for (int xx = 0; xx <= x; xx++) {
			for (int yy = 0; yy <= y; yy++) {
				ans = max(ans, dp[i][xx][yy]);
			}
		}
	}
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...