Submission #287375

# Submission time Handle Problem Language Result Execution time Memory
287375 2020-08-31T16:32:41 Z Berted Gift (IZhO18_nicegift) C++14
100 / 100
794 ms 149624 KB
#include <iostream>
#include <list>
#include <vector>
#include <algorithm>
#define ll long long
#define vi vector<int>
#define piv pair<ll, vector<int>>
#define pii pair<ll, int>
#define fst first
#define snd second
using namespace std;

int N, K;
ll S = 0;
pii A[1000001];
list<piv> L;

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> N >> K;
	for (int i = 0; i < N; i++) {cin >> A[i].fst; A[i].snd = i; S += A[i].fst;}
	
	if (S % K) {cout << "-1\n";}
	else
	{
		sort(A, A + N, greater<pii>()); S /= K;
		if (A[0].fst <= S)
		{
			L.push_back({S, vi()});
			auto it = L.begin();
			for (int i = 0; i < N; i++)
			{
				while (A[i].fst)
				{
					if (it -> fst > A[i].fst)
					{
						it -> fst -= A[i].fst;
						vector<int> cpy = it -> snd;
						cpy.push_back(A[i].snd + 1);
						L.insert(it, make_pair(A[i].fst, cpy));
						A[i].fst = 0;
					}
					else
					{
						A[i].fst -= it -> fst;
						it -> snd.push_back(A[i].snd + 1);
						it = next(it);
						if (it == L.end()) {it = L.begin();}
					}
				}
			}
			cout << L.size() << "\n";
			for (const auto &x : L)
			{
				cout << x.fst;
				for (const auto &y : x.snd) {cout << " " << y;}
				cout << "\n";
			}
		}
		else {cout << "-1\n";}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 1 ms 384 KB n=3
3 Correct 1 ms 384 KB n=3
4 Correct 1 ms 288 KB n=4
5 Correct 1 ms 384 KB n=4
6 Correct 0 ms 384 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 1 ms 384 KB n=3
3 Correct 1 ms 384 KB n=3
4 Correct 1 ms 288 KB n=4
5 Correct 1 ms 384 KB n=4
6 Correct 0 ms 384 KB n=2
7 Correct 1 ms 384 KB n=5
8 Correct 1 ms 384 KB n=8
9 Correct 1 ms 384 KB n=14
10 Correct 1 ms 384 KB n=11
11 Correct 31 ms 6648 KB n=50000
12 Correct 32 ms 6656 KB n=50000
13 Correct 1 ms 384 KB n=10
14 Correct 1 ms 384 KB n=685
15 Correct 1 ms 384 KB n=623
16 Correct 1 ms 512 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 1 ms 384 KB n=3
3 Correct 1 ms 384 KB n=3
4 Correct 1 ms 288 KB n=4
5 Correct 1 ms 384 KB n=4
6 Correct 0 ms 384 KB n=2
7 Correct 1 ms 384 KB n=5
8 Correct 1 ms 384 KB n=8
9 Correct 1 ms 384 KB n=14
10 Correct 1 ms 384 KB n=11
11 Correct 31 ms 6648 KB n=50000
12 Correct 32 ms 6656 KB n=50000
13 Correct 1 ms 384 KB n=10
14 Correct 1 ms 384 KB n=685
15 Correct 1 ms 384 KB n=623
16 Correct 1 ms 512 KB n=973
17 Correct 2 ms 512 KB n=989
18 Correct 1 ms 488 KB n=563
19 Correct 2 ms 512 KB n=592
20 Correct 2 ms 512 KB n=938
21 Correct 2 ms 512 KB n=747
22 Correct 2 ms 512 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 454 ms 90632 KB n=1000000
2 Correct 281 ms 48504 KB n=666666
3 Correct 178 ms 27188 KB n=400000
4 Correct 375 ms 63480 KB n=285714
5 Correct 10 ms 1152 KB n=20000
6 Correct 317 ms 49656 KB n=181818
7 Correct 4 ms 768 KB n=10000
8 Correct 34 ms 4216 KB n=6666
9 Correct 2 ms 488 KB n=4000
10 Correct 210 ms 22264 KB n=2857
11 Correct 1 ms 512 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 1 ms 384 KB n=3
3 Correct 1 ms 384 KB n=3
4 Correct 1 ms 288 KB n=4
5 Correct 1 ms 384 KB n=4
6 Correct 0 ms 384 KB n=2
7 Correct 1 ms 384 KB n=5
8 Correct 1 ms 384 KB n=8
9 Correct 1 ms 384 KB n=14
10 Correct 1 ms 384 KB n=11
11 Correct 31 ms 6648 KB n=50000
12 Correct 32 ms 6656 KB n=50000
13 Correct 1 ms 384 KB n=10
14 Correct 1 ms 384 KB n=685
15 Correct 1 ms 384 KB n=623
16 Correct 1 ms 512 KB n=973
17 Correct 2 ms 512 KB n=989
18 Correct 1 ms 488 KB n=563
19 Correct 2 ms 512 KB n=592
20 Correct 2 ms 512 KB n=938
21 Correct 2 ms 512 KB n=747
22 Correct 2 ms 512 KB n=991
23 Correct 454 ms 90632 KB n=1000000
24 Correct 281 ms 48504 KB n=666666
25 Correct 178 ms 27188 KB n=400000
26 Correct 375 ms 63480 KB n=285714
27 Correct 10 ms 1152 KB n=20000
28 Correct 317 ms 49656 KB n=181818
29 Correct 4 ms 768 KB n=10000
30 Correct 34 ms 4216 KB n=6666
31 Correct 2 ms 488 KB n=4000
32 Correct 210 ms 22264 KB n=2857
33 Correct 1 ms 512 KB n=2000
34 Correct 16 ms 3456 KB n=23514
35 Correct 18 ms 3456 KB n=23514
36 Correct 1 ms 512 KB n=940
37 Correct 0 ms 384 KB n=2
38 Correct 102 ms 16760 KB n=100000
39 Correct 118 ms 16760 KB n=100000
40 Correct 1 ms 384 KB n=10
41 Correct 1 ms 384 KB n=100
42 Correct 6 ms 1024 KB n=1000
43 Correct 629 ms 137336 KB n=1000000
44 Correct 794 ms 149624 KB n=1000000
45 Correct 640 ms 104720 KB n=666666
46 Correct 519 ms 76620 KB n=400000
47 Correct 197 ms 21880 KB n=2336
48 Correct 399 ms 63480 KB n=285714
49 Correct 320 ms 49656 KB n=181818
50 Correct 266 ms 28536 KB n=40000
51 Correct 228 ms 25464 KB n=20000
52 Correct 197 ms 23160 KB n=10000
53 Correct 202 ms 23440 KB n=6666
54 Correct 174 ms 19704 KB n=4000
55 Correct 206 ms 22136 KB n=2857
56 Correct 96 ms 11000 KB n=2000