Submission #789204

# Submission time Handle Problem Language Result Execution time Memory
789204 2023-07-21T07:39:35 Z 박상훈(#10042) Cookies (JOI23_cookies) C++17
0 / 100
7 ms 692 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int n, m, a[100100], b[100100];

void output(int a1, int a2, int x1, int x2){
	priority_queue<pair<int, int>> pq;
	for (int i=1;i<=n;i++) pq.emplace(a[i], i);

	a1 = b[a1];
	a2 = b[a2];
	if (a1 < a2){
		swap(a1, a2);
		swap(x1, x2);
	}

	// printf("ok %d %d %d %d\n", a1, a2, x1, x2);

	vector<vector<int>> ans;
	for (int z=0;z<x1;z++){
		assert((int)pq.size() >= a1);
		vector<int> buf;
		vector<pair<int, int>> buf2;

		for (int i=0;i<a1;i++){
			buf.push_back(pq.top().second);
			if (pq.top().first > 1) buf2.emplace_back(pq.top().first - 1, pq.top().second);

			pq.pop();
		}

		ans.push_back(buf);
	}

	for (int z=0;z<x2;z++){
		assert((int)pq.size() >= a2);
		vector<int> buf;
		vector<pair<int, int>> buf2;

		for (int i=0;i<a2;i++){
			buf.push_back(pq.top().second);
			if (pq.top().first > 1) buf2.emplace_back(pq.top().first - 1, pq.top().second);

			pq.pop();
		}

		ans.push_back(buf);
	}

	printf("%d\n", (int)ans.size());
	for (auto &V:ans){
		printf("%d ", (int)V.size());
		for (auto &x:V) printf("%d ", x);
		printf("\n");
	}
}

int main(){
	int sum = 0, mx;
	
	scanf("%d", &n);
	for (int i=1;i<=n;i++){
		scanf("%d", a+i);
		sum += a[i];
	} 
	mx = *max_element(a+1, a+n+1);

	scanf("%d", &m);
	for (int i=1;i<=m;i++) scanf("%d", b+i);

	vector<array<int, 5>> ans;
	for (int i=1;i<=m;i++){
		if (sum % b[i] == 0 && sum / b[i] >= mx){
			ans.push_back({sum/b[i], i, i, sum/b[i], 0});
		}

		for (int j=1;j<i;j++){
			for (int k=1;b[j]*k <= sum;k++){
				int rem = sum - b[j]*k;
				int l = rem / b[i];
				if (b[i]*l + b[j]*k == sum && l+k >= mx){
					ans.push_back({l+k, i, j, l, k});
				}
			}
		}
	}

	if (ans.empty()){
		printf("-1\n");
	}
	else{
		auto tmp = *min_element(ans.begin(), ans.end());
		output(tmp[1], tmp[2], tmp[3], tmp[4]);
	}
}

Compilation message

cookies.cpp: In function 'int main()':
cookies.cpp:62:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
cookies.cpp:64:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |   scanf("%d", a+i);
      |   ~~~~~^~~~~~~~~~~
cookies.cpp:69:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |  scanf("%d", &m);
      |  ~~~~~^~~~~~~~~~
cookies.cpp:70:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |  for (int i=1;i<=m;i++) scanf("%d", b+i);
      |                         ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 7 ms 692 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Incorrect 1 ms 212 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Runtime error 1 ms 468 KB Execution killed with signal 6
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Runtime error 1 ms 468 KB Execution killed with signal 6
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 7 ms 692 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Incorrect 1 ms 212 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 7 ms 692 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Incorrect 1 ms 212 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 7 ms 692 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Incorrect 1 ms 212 KB Output isn't correct
20 Halted 0 ms 0 KB -