Submission #40451

# Submission time Handle Problem Language Result Execution time Memory
40451 2018-02-01T15:11:06 Z szawinis Gift (IZhO18_nicegift) C++14
30 / 100
206 ms 28136 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++) {
		assert(ls[i].size() == k);
		printf("1 ");
		for(int idx: ls[i]) printf("%d ", idx+1);
		printf("\n");
	}
}

Compilation message

In file included from /usr/include/c++/5/cassert:43:0,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:33,
                 from nicegift.cpp:1:
nicegift.cpp: In function 'int main()':
nicegift.cpp:29:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   assert(ls[i].size() == k);
                       ^
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 Correct 19 ms 23800 KB n=4
2 Correct 20 ms 23912 KB n=3
3 Correct 20 ms 23980 KB n=3
4 Correct 19 ms 23980 KB n=4
5 Correct 19 ms 23980 KB n=4
6 Correct 19 ms 24024 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23800 KB n=4
2 Correct 20 ms 23912 KB n=3
3 Correct 20 ms 23980 KB n=3
4 Correct 19 ms 23980 KB n=4
5 Correct 19 ms 23980 KB n=4
6 Correct 19 ms 24024 KB n=2
7 Correct 19 ms 24024 KB n=5
8 Correct 33 ms 27088 KB n=8
9 Correct 35 ms 27088 KB n=14
10 Correct 27 ms 27088 KB n=11
11 Correct 71 ms 28136 KB n=50000
12 Correct 75 ms 28136 KB n=50000
13 Correct 62 ms 28136 KB n=10
14 Correct 56 ms 28136 KB n=685
15 Correct 58 ms 28136 KB n=623
16 Correct 43 ms 28136 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23800 KB n=4
2 Correct 20 ms 23912 KB n=3
3 Correct 20 ms 23980 KB n=3
4 Correct 19 ms 23980 KB n=4
5 Correct 19 ms 23980 KB n=4
6 Correct 19 ms 24024 KB n=2
7 Correct 19 ms 24024 KB n=5
8 Correct 33 ms 27088 KB n=8
9 Correct 35 ms 27088 KB n=14
10 Correct 27 ms 27088 KB n=11
11 Correct 71 ms 28136 KB n=50000
12 Correct 75 ms 28136 KB n=50000
13 Correct 62 ms 28136 KB n=10
14 Correct 56 ms 28136 KB n=685
15 Correct 58 ms 28136 KB n=623
16 Correct 43 ms 28136 KB n=973
17 Correct 58 ms 28136 KB n=989
18 Correct 38 ms 28136 KB n=563
19 Correct 50 ms 28136 KB n=592
20 Correct 60 ms 28136 KB n=938
21 Correct 45 ms 28136 KB n=747
22 Correct 48 ms 28136 KB n=991
# Verdict Execution time Memory Grader output
1 Incorrect 206 ms 28136 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23800 KB n=4
2 Correct 20 ms 23912 KB n=3
3 Correct 20 ms 23980 KB n=3
4 Correct 19 ms 23980 KB n=4
5 Correct 19 ms 23980 KB n=4
6 Correct 19 ms 24024 KB n=2
7 Correct 19 ms 24024 KB n=5
8 Correct 33 ms 27088 KB n=8
9 Correct 35 ms 27088 KB n=14
10 Correct 27 ms 27088 KB n=11
11 Correct 71 ms 28136 KB n=50000
12 Correct 75 ms 28136 KB n=50000
13 Correct 62 ms 28136 KB n=10
14 Correct 56 ms 28136 KB n=685
15 Correct 58 ms 28136 KB n=623
16 Correct 43 ms 28136 KB n=973
17 Correct 58 ms 28136 KB n=989
18 Correct 38 ms 28136 KB n=563
19 Correct 50 ms 28136 KB n=592
20 Correct 60 ms 28136 KB n=938
21 Correct 45 ms 28136 KB n=747
22 Correct 48 ms 28136 KB n=991
23 Incorrect 206 ms 28136 KB Not all heaps are empty in the end
24 Halted 0 ms 0 KB -