Submission #40450

# Submission time Handle Problem Language Result Execution time Memory
40450 2018-02-01T15:09:41 Z szawinis Gift (IZhO18_nicegift) C++14
0 / 100
201 ms 27920 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+1;

int n, k, a[N];
vector<int> ls[N];
int main() {
	scanf("%d %d", &n, &k);
	int sum = 0;
	for(int i = 0; i < n; i++) scanf("%d", a+i), sum += a[i];
	if(sum % k) printf("-1"), exit(0);
	priority_queue<pair<int,int> > pq;
	for(int i = 0; i < sum / k; i++) pq.emplace(k, i);
	for(int i = 0; i < n; i++) {
		unordered_set<int> mark;
		for(int j = 0; j < a[i]; j++) {
			assert(!pq.empty());
			auto curr = pq.top();
			pq.pop();
			--curr.first;
			if(mark.count(curr.second)) printf("-1"), exit(0);
			ls[curr.second].push_back(i);
			pq.push(curr);
			mark.insert(curr.second);
		}
	}
	printf("%d\n", sum / k);
	for(int i = 0; i < sum / k; i++) {
		printf("%d ", ls[i].size());
		for(int idx: ls[i]) printf("%d ", idx+1);
		printf("\n");
	}
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:29:29: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
   printf("%d ", ls[i].size());
                             ^
nicegift.cpp:8:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &k);
                        ^
nicegift.cpp:10:58: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < n; i++) scanf("%d", a+i), sum += a[i];
                                                          ^
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 23800 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 23800 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 23800 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 201 ms 27920 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 23800 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -