Submission #511093

# Submission time Handle Problem Language Result Execution time Memory
511093 2022-01-15T05:57:01 Z Mazaalai Gift (IZhO18_nicegift) C++17
30 / 100
397 ms 55056 KB
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define LLA(x) x.rbegin(),x.rend()
#define print(x) for(auto el:x)cout<<el<<' ';cout<<"\n";
#define printPII(x) for(auto [a,b]:x)cout<<a<<","<<b<<' ';cout<<'\n';
using namespace std;
using PII = pair <int, int>;
using ll = long long;
ll n, k, onePick = 1;
bool impossible;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	cin >> n >> k;
	vector <vector <ll> > ans;
	set <PII> bfs;
	ll sum = 0;
	vector <ll> vals;
	for (int i = 1; i <= n; i++) {
		ll x; cin >> x;
		sum += x;
		vals.pb(x);
		bfs.insert({x, i});
	}
	sort(LLA(vals));
	if (sum % k != 0) {
		cout << "-1\n";
		return 0;
	}
	if (vals[0] == vals.back()) {
		ll cycleLen = k * n / gcd(k, n); // 4, 6, 2-> 12
		ll oneCycleContribution = cycleLen / n; // 
		onePick = vals[0] / oneCycleContribution;
		for (auto& el : vals) el /= onePick;
		sum /= onePick;
	}
	while(!impossible && sum > 0) {
		vector <ll> pick(1, onePick);
		vector <PII> add;
		for (int i = 0; i < k; i++) {
			auto it = --bfs.end();
			PII cur = *it;
			bfs.erase(it);
			pick.pb(cur.ss);
			cur.ff--;
			sum--;
			if (cur.ff < 0) {
				impossible = 1;
				break;
			}
			add.pb(cur);
		}
		ans.pb(pick);
		for (auto el : add) bfs.insert(el);
	}
	// int dbg = 0;
	if (impossible) {
		cout << "-1\n";
		return 0;
	}
	cout << ans.size() << '\n';
	for (auto el : ans) {
		print(el);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB n=4
2 Correct 0 ms 204 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 1 ms 292 KB n=4
5 Correct 1 ms 296 KB n=4
6 Correct 0 ms 312 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB n=4
2 Correct 0 ms 204 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 1 ms 292 KB n=4
5 Correct 1 ms 296 KB n=4
6 Correct 0 ms 312 KB n=2
7 Correct 1 ms 204 KB n=5
8 Correct 4 ms 972 KB n=8
9 Correct 9 ms 1160 KB n=14
10 Correct 7 ms 972 KB n=11
11 Correct 58 ms 6624 KB n=50000
12 Correct 49 ms 6600 KB n=50000
13 Correct 27 ms 3416 KB n=10
14 Correct 29 ms 2988 KB n=685
15 Correct 31 ms 3304 KB n=623
16 Correct 18 ms 1976 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB n=4
2 Correct 0 ms 204 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 1 ms 292 KB n=4
5 Correct 1 ms 296 KB n=4
6 Correct 0 ms 312 KB n=2
7 Correct 1 ms 204 KB n=5
8 Correct 4 ms 972 KB n=8
9 Correct 9 ms 1160 KB n=14
10 Correct 7 ms 972 KB n=11
11 Correct 58 ms 6624 KB n=50000
12 Correct 49 ms 6600 KB n=50000
13 Correct 27 ms 3416 KB n=10
14 Correct 29 ms 2988 KB n=685
15 Correct 31 ms 3304 KB n=623
16 Correct 18 ms 1976 KB n=973
17 Correct 33 ms 2992 KB n=989
18 Correct 13 ms 1188 KB n=563
19 Correct 21 ms 1668 KB n=592
20 Correct 20 ms 1732 KB n=938
21 Correct 17 ms 1360 KB n=747
22 Correct 19 ms 1508 KB n=991
# Verdict Execution time Memory Grader output
1 Incorrect 397 ms 55056 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB n=4
2 Correct 0 ms 204 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 1 ms 292 KB n=4
5 Correct 1 ms 296 KB n=4
6 Correct 0 ms 312 KB n=2
7 Correct 1 ms 204 KB n=5
8 Correct 4 ms 972 KB n=8
9 Correct 9 ms 1160 KB n=14
10 Correct 7 ms 972 KB n=11
11 Correct 58 ms 6624 KB n=50000
12 Correct 49 ms 6600 KB n=50000
13 Correct 27 ms 3416 KB n=10
14 Correct 29 ms 2988 KB n=685
15 Correct 31 ms 3304 KB n=623
16 Correct 18 ms 1976 KB n=973
17 Correct 33 ms 2992 KB n=989
18 Correct 13 ms 1188 KB n=563
19 Correct 21 ms 1668 KB n=592
20 Correct 20 ms 1732 KB n=938
21 Correct 17 ms 1360 KB n=747
22 Correct 19 ms 1508 KB n=991
23 Incorrect 397 ms 55056 KB Jury has the answer but participant has not
24 Halted 0 ms 0 KB -