Submission #1025492

# Submission time Handle Problem Language Result Execution time Memory
1025492 2024-07-17T05:26:16 Z TheWilp Jelly Flavours (IOI20_jelly) C++14
24 / 100
65 ms 860 KB
#include "jelly.h"
#include <vector>
#include <algorithm>
#include <map>

const int MAXMONEY = 10005;

class name{
public:
	int x;
	int y;
	bool operator<(const name& other) const{
		return x < other.x;
	}
};

class node{
public:
	int value;
	int count;
	node* left = nullptr;
	node* right = nullptr;
};

int get_mid(int left,int right) {
	return (right - left) / 2 + left;
}

int get_value(node* root) {
	if(!root) return 0;
	return root->value;
}

int get_count(node* root) {
	if(!root) return 0;
	return root->count;
}

void add(node* root,int pos,int value,int left = 0,int right = MAXMONEY) {
	if(right == left) {
		root->value = value;
		root->count = 1;
		return;
	}
	int mid = get_mid(left,right);
	if(pos <= mid) {
		if(root->left == nullptr) root->left = new node();
		add(root->left,pos,value,left,mid);
	}
	else {
		if(root->right == nullptr) root->right = new node();
		add(root->right,pos,value,mid + 1,right);
	}
	root->value = get_value(root->left) + get_value(root->right);
	root->count = get_count(root->left) + get_count(root->right);
}

int get_max_count(node* root,int max_value,int left = 0,int right = MAXMONEY) {
	if(!root) return 0;
	int mid = get_mid(left,right);
	if(max_value >= get_value(root->left)) {
		return get_count(root->left) + get_max_count(root->right,max_value - get_value(root->left),mid + 1,right);
	}
	else {
		return get_max_count(root->left,max_value,left,mid);
	}
}

int find_maximum_unique(int x, int y, std::vector<int> a, std::vector<int> b) {
	int N = a.size();
	int ans = 0;
	std::vector<name> v(N);
	for(int q = 0;q < N;q++) {
		v[q].x = a[q];
		v[q].y = b[q];
	}
	std::sort(v.begin(),v.end());
	std::vector<int> dp(MAXMONEY,20000);
	dp[0] = 0;
	std::vector<int> res(N,20000);
	int min_require = 0;
	for(int q = 0;q < N;q++) {
		min_require += v[q].x;
		for(int w = MAXMONEY - 1;w>=0;w--) {
			if(w < v[q].x) break;
			dp[w] = std::min(dp[w],dp[w - v[q].x] + v[q].y);
		}
		for(int w = std::max(0,min_require - x);w < MAXMONEY;w++) {
			if(dp[w] <= y) {
				res[q] = std::min(res[q],dp[w]);
			}
		}
	}
	if(res.back() <= y) return N;

	std::vector<name> u(N);
	for(int q = 0;q < N;q++) {
		u[q].x = v[q].y;
		u[q].y = q;
	}
	std::sort(u.begin(),u.end());
	std::map<int,int> mm;
	for(int q = 0;q < N;q++) {
		mm[u[q].y] = q;
	}
	
	node* root = new node();
	for(int q = N - 1;q>=1;q--) {
		add(root,mm[q],u[q].x);
		if(res[q - 1] <= y) {
			int remain_value = y - res[q];
			ans = std::max(ans,q + get_max_count(root,remain_value));
		}
	}
	add(root,mm[0],u[0].x);
	ans = std::max(ans,get_max_count(root,y));

	return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '8', found: '7'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '8', found: '7'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 604 KB 1st lines differ - on the 1st token, expected: '689', found: '66'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 716 KB Output is correct
2 Correct 12 ms 528 KB Output is correct
3 Correct 12 ms 604 KB Output is correct
4 Correct 55 ms 512 KB Output is correct
5 Correct 50 ms 348 KB Output is correct
6 Correct 12 ms 600 KB Output is correct
7 Correct 12 ms 604 KB Output is correct
8 Correct 11 ms 604 KB Output is correct
9 Correct 45 ms 500 KB Output is correct
10 Correct 48 ms 344 KB Output is correct
11 Correct 23 ms 604 KB Output is correct
12 Correct 32 ms 596 KB Output is correct
13 Correct 23 ms 600 KB Output is correct
14 Correct 31 ms 344 KB Output is correct
15 Correct 32 ms 520 KB Output is correct
16 Correct 23 ms 528 KB Output is correct
17 Correct 13 ms 604 KB Output is correct
18 Correct 15 ms 600 KB Output is correct
19 Correct 37 ms 596 KB Output is correct
20 Correct 33 ms 592 KB Output is correct
21 Correct 12 ms 604 KB Output is correct
22 Correct 12 ms 604 KB Output is correct
23 Correct 12 ms 604 KB Output is correct
24 Correct 46 ms 512 KB Output is correct
25 Correct 65 ms 348 KB Output is correct
26 Correct 12 ms 600 KB Output is correct
27 Correct 12 ms 604 KB Output is correct
28 Correct 11 ms 604 KB Output is correct
29 Correct 45 ms 500 KB Output is correct
30 Correct 47 ms 344 KB Output is correct
31 Correct 21 ms 592 KB Output is correct
32 Correct 31 ms 516 KB Output is correct
33 Correct 22 ms 592 KB Output is correct
34 Correct 31 ms 344 KB Output is correct
35 Correct 34 ms 604 KB Output is correct
36 Correct 23 ms 516 KB Output is correct
37 Correct 13 ms 604 KB Output is correct
38 Correct 12 ms 532 KB Output is correct
39 Correct 37 ms 596 KB Output is correct
40 Correct 33 ms 592 KB Output is correct
41 Correct 12 ms 604 KB Output is correct
42 Correct 12 ms 532 KB Output is correct
43 Correct 12 ms 600 KB Output is correct
44 Correct 48 ms 512 KB Output is correct
45 Correct 48 ms 348 KB Output is correct
46 Correct 12 ms 536 KB Output is correct
47 Correct 12 ms 604 KB Output is correct
48 Correct 11 ms 604 KB Output is correct
49 Correct 46 ms 428 KB Output is correct
50 Correct 48 ms 348 KB Output is correct
51 Correct 21 ms 604 KB Output is correct
52 Correct 31 ms 596 KB Output is correct
53 Correct 23 ms 596 KB Output is correct
54 Correct 31 ms 348 KB Output is correct
55 Correct 32 ms 592 KB Output is correct
56 Correct 23 ms 592 KB Output is correct
57 Correct 12 ms 600 KB Output is correct
58 Correct 12 ms 600 KB Output is correct
59 Correct 37 ms 496 KB Output is correct
60 Correct 45 ms 520 KB Output is correct
61 Correct 12 ms 600 KB Output is correct
62 Correct 12 ms 604 KB Output is correct
63 Correct 13 ms 600 KB Output is correct
64 Correct 46 ms 512 KB Output is correct
65 Correct 52 ms 348 KB Output is correct
66 Correct 12 ms 604 KB Output is correct
67 Correct 13 ms 528 KB Output is correct
68 Correct 12 ms 604 KB Output is correct
69 Correct 49 ms 348 KB Output is correct
70 Correct 48 ms 348 KB Output is correct
71 Correct 21 ms 604 KB Output is correct
72 Correct 31 ms 512 KB Output is correct
73 Correct 22 ms 592 KB Output is correct
74 Correct 31 ms 348 KB Output is correct
75 Correct 32 ms 596 KB Output is correct
76 Correct 23 ms 592 KB Output is correct
77 Correct 20 ms 604 KB Output is correct
78 Correct 12 ms 536 KB Output is correct
79 Correct 37 ms 516 KB Output is correct
80 Correct 33 ms 592 KB Output is correct
81 Correct 12 ms 600 KB Output is correct
82 Correct 12 ms 528 KB Output is correct
83 Correct 12 ms 600 KB Output is correct
84 Correct 46 ms 596 KB Output is correct
85 Correct 48 ms 344 KB Output is correct
86 Correct 12 ms 604 KB Output is correct
87 Correct 12 ms 604 KB Output is correct
88 Correct 11 ms 532 KB Output is correct
89 Correct 46 ms 348 KB Output is correct
90 Correct 48 ms 348 KB Output is correct
91 Correct 21 ms 604 KB Output is correct
92 Correct 31 ms 592 KB Output is correct
93 Correct 25 ms 524 KB Output is correct
94 Correct 31 ms 348 KB Output is correct
95 Correct 32 ms 596 KB Output is correct
96 Correct 23 ms 600 KB Output is correct
97 Correct 13 ms 600 KB Output is correct
98 Correct 12 ms 604 KB Output is correct
99 Correct 37 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 520 KB Output is correct
2 Correct 15 ms 604 KB Output is correct
3 Correct 12 ms 604 KB Output is correct
4 Correct 47 ms 428 KB Output is correct
5 Correct 45 ms 516 KB Output is correct
6 Correct 12 ms 604 KB Output is correct
7 Correct 13 ms 604 KB Output is correct
8 Correct 12 ms 708 KB Output is correct
9 Correct 47 ms 344 KB Output is correct
10 Correct 48 ms 348 KB Output is correct
11 Correct 20 ms 612 KB Output is correct
12 Correct 34 ms 596 KB Output is correct
13 Correct 18 ms 512 KB Output is correct
14 Correct 32 ms 512 KB Output is correct
15 Correct 35 ms 344 KB Output is correct
16 Correct 19 ms 856 KB Output is correct
17 Correct 19 ms 604 KB Output is correct
18 Correct 19 ms 604 KB Output is correct
19 Correct 33 ms 524 KB Output is correct
20 Correct 34 ms 528 KB Output is correct
21 Correct 21 ms 600 KB Output is correct
22 Correct 13 ms 604 KB Output is correct
23 Correct 13 ms 532 KB Output is correct
24 Correct 57 ms 348 KB Output is correct
25 Correct 46 ms 596 KB Output is correct
26 Correct 14 ms 604 KB Output is correct
27 Correct 13 ms 600 KB Output is correct
28 Correct 12 ms 860 KB Output is correct
29 Correct 55 ms 348 KB Output is correct
30 Correct 49 ms 500 KB Output is correct
31 Correct 20 ms 604 KB Output is correct
32 Correct 32 ms 496 KB Output is correct
33 Correct 19 ms 604 KB Output is correct
34 Correct 32 ms 512 KB Output is correct
35 Correct 36 ms 344 KB Output is correct
36 Correct 19 ms 516 KB Output is correct
37 Correct 20 ms 528 KB Output is correct
38 Correct 21 ms 600 KB Output is correct
39 Correct 35 ms 596 KB Output is correct
40 Correct 34 ms 516 KB Output is correct
41 Correct 21 ms 600 KB Output is correct
42 Correct 13 ms 604 KB Output is correct
43 Correct 13 ms 532 KB Output is correct
44 Correct 47 ms 348 KB Output is correct
45 Correct 50 ms 500 KB Output is correct
46 Correct 12 ms 604 KB Output is correct
47 Correct 13 ms 596 KB Output is correct
48 Correct 12 ms 604 KB Output is correct
49 Correct 48 ms 504 KB Output is correct
50 Correct 48 ms 344 KB Output is correct
51 Correct 20 ms 604 KB Output is correct
52 Correct 32 ms 520 KB Output is correct
53 Correct 19 ms 520 KB Output is correct
54 Correct 32 ms 596 KB Output is correct
55 Correct 36 ms 348 KB Output is correct
56 Correct 19 ms 596 KB Output is correct
57 Correct 19 ms 600 KB Output is correct
58 Correct 19 ms 520 KB Output is correct
59 Correct 34 ms 516 KB Output is correct
60 Correct 34 ms 516 KB Output is correct
61 Correct 27 ms 592 KB Output is correct
62 Correct 13 ms 600 KB Output is correct
63 Correct 13 ms 604 KB Output is correct
64 Correct 47 ms 344 KB Output is correct
65 Correct 45 ms 592 KB Output is correct
66 Correct 17 ms 600 KB Output is correct
67 Correct 13 ms 704 KB Output is correct
68 Correct 12 ms 528 KB Output is correct
69 Correct 50 ms 500 KB Output is correct
70 Correct 49 ms 348 KB Output is correct
71 Correct 20 ms 604 KB Output is correct
72 Correct 32 ms 604 KB Output is correct
73 Correct 19 ms 604 KB Output is correct
74 Correct 32 ms 516 KB Output is correct
75 Correct 35 ms 344 KB Output is correct
76 Correct 19 ms 596 KB Output is correct
77 Correct 19 ms 600 KB Output is correct
78 Correct 21 ms 528 KB Output is correct
79 Correct 34 ms 604 KB Output is correct
80 Correct 34 ms 596 KB Output is correct
81 Correct 21 ms 600 KB Output is correct
82 Correct 13 ms 600 KB Output is correct
83 Correct 13 ms 532 KB Output is correct
84 Correct 47 ms 436 KB Output is correct
85 Correct 45 ms 512 KB Output is correct
86 Correct 12 ms 600 KB Output is correct
87 Correct 13 ms 708 KB Output is correct
88 Correct 12 ms 604 KB Output is correct
89 Correct 47 ms 500 KB Output is correct
90 Correct 49 ms 504 KB Output is correct
91 Correct 21 ms 592 KB Output is correct
92 Correct 32 ms 596 KB Output is correct
93 Correct 19 ms 600 KB Output is correct
94 Correct 32 ms 592 KB Output is correct
95 Correct 38 ms 348 KB Output is correct
96 Correct 19 ms 600 KB Output is correct
97 Correct 20 ms 604 KB Output is correct
98 Correct 19 ms 592 KB Output is correct
99 Correct 34 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '8', found: '7'
2 Halted 0 ms 0 KB -