# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
378651 |
2021-03-17T02:50:10 Z |
syl123456 |
Gift (IZhO18_nicegift) |
C++17 |
|
2000 ms |
329412 KB |
#include <bits/stdc++.h>
#define all(i) i.begin(), i.end()
#define rall(i) i.rbegin(), i.rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, int> pl;
ll gcd(ll i, ll j) {
if (j == 0) return i;
return i % j ? gcd(j, i % j) : j;
}
ll lcm(ll i, ll j) {
return i * j / gcd(i, j);
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, k;
cin >> n >> k;
ll a[n], sum = 0, mx = 0;
priority_queue<pl> pq;
for (int i = 0; i < n; ++i) cin >> a[i], sum += a[i], mx = max(mx, a[i]), pq.emplace(a[i], i);
if (sum % k != 0 || mx > sum / k) return cout << -1, 0;
if (sum / n == mx) {
ll x = sum / lcm(n, k), t = sum / (x * k);
cout << t << '\n';
for (int i = 0, _t = 0; _t < t; ++_t) {
cout << x;
for (int j = 0; j < k; ++j) {
cout << ' ' << ++i;
if (i == n) i = 0;
}
cout << '\n';
}
return 0;
}
vector<int> v;
vector<vector<int>> ans;
while (sum > 0) {
for (int i = 0; i < k; ++i)
v.push_back(pq.top().second), pq.pop();
if (a[v.back()] == sum / k) {
ans.emplace_back(1, sum / k);
for (int i : v) ans.back().push_back(i + 1);
break;
}
ll x = max(1ll, a[v.back()] - pq.top().first);
ans.emplace_back(1, x);
while (!v.empty()) {
int i = v.back();
v.pop_back();
ans.back().push_back(i + 1);
a[i] -= x, sum -= x;
pq.emplace(a[i], i);
}
}
cout << ans.size() << '\n';
for (auto i : ans) {
for (int j : i) cout << j << ' ';
cout << '\n';
}
}
/*
* sum % k == 0 && max <= sum / k
* sum / lcm(n, k)
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
0 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
9 ms |
1192 KB |
n=14 |
10 |
Correct |
5 ms |
876 KB |
n=11 |
11 |
Correct |
28 ms |
3816 KB |
n=50000 |
12 |
Correct |
39 ms |
4836 KB |
n=50000 |
13 |
Correct |
28 ms |
2852 KB |
n=10 |
14 |
Correct |
29 ms |
3104 KB |
n=685 |
15 |
Correct |
35 ms |
3360 KB |
n=623 |
16 |
Correct |
18 ms |
2084 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
0 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
9 ms |
1192 KB |
n=14 |
10 |
Correct |
5 ms |
876 KB |
n=11 |
11 |
Correct |
28 ms |
3816 KB |
n=50000 |
12 |
Correct |
39 ms |
4836 KB |
n=50000 |
13 |
Correct |
28 ms |
2852 KB |
n=10 |
14 |
Correct |
29 ms |
3104 KB |
n=685 |
15 |
Correct |
35 ms |
3360 KB |
n=623 |
16 |
Correct |
18 ms |
2084 KB |
n=973 |
17 |
Correct |
30 ms |
2596 KB |
n=989 |
18 |
Correct |
15 ms |
1260 KB |
n=563 |
19 |
Correct |
21 ms |
1516 KB |
n=592 |
20 |
Correct |
21 ms |
1388 KB |
n=938 |
21 |
Correct |
16 ms |
1388 KB |
n=747 |
22 |
Correct |
19 ms |
1260 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
380 ms |
38076 KB |
n=1000000 |
2 |
Correct |
238 ms |
23868 KB |
n=666666 |
3 |
Correct |
134 ms |
13648 KB |
n=400000 |
4 |
Correct |
286 ms |
24144 KB |
n=285714 |
5 |
Correct |
7 ms |
1136 KB |
n=20000 |
6 |
Correct |
248 ms |
19932 KB |
n=181818 |
7 |
Correct |
4 ms |
752 KB |
n=10000 |
8 |
Correct |
31 ms |
2284 KB |
n=6666 |
9 |
Correct |
2 ms |
492 KB |
n=4000 |
10 |
Correct |
184 ms |
9964 KB |
n=2857 |
11 |
Correct |
1 ms |
364 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
0 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
9 ms |
1192 KB |
n=14 |
10 |
Correct |
5 ms |
876 KB |
n=11 |
11 |
Correct |
28 ms |
3816 KB |
n=50000 |
12 |
Correct |
39 ms |
4836 KB |
n=50000 |
13 |
Correct |
28 ms |
2852 KB |
n=10 |
14 |
Correct |
29 ms |
3104 KB |
n=685 |
15 |
Correct |
35 ms |
3360 KB |
n=623 |
16 |
Correct |
18 ms |
2084 KB |
n=973 |
17 |
Correct |
30 ms |
2596 KB |
n=989 |
18 |
Correct |
15 ms |
1260 KB |
n=563 |
19 |
Correct |
21 ms |
1516 KB |
n=592 |
20 |
Correct |
21 ms |
1388 KB |
n=938 |
21 |
Correct |
16 ms |
1388 KB |
n=747 |
22 |
Correct |
19 ms |
1260 KB |
n=991 |
23 |
Correct |
380 ms |
38076 KB |
n=1000000 |
24 |
Correct |
238 ms |
23868 KB |
n=666666 |
25 |
Correct |
134 ms |
13648 KB |
n=400000 |
26 |
Correct |
286 ms |
24144 KB |
n=285714 |
27 |
Correct |
7 ms |
1136 KB |
n=20000 |
28 |
Correct |
248 ms |
19932 KB |
n=181818 |
29 |
Correct |
4 ms |
752 KB |
n=10000 |
30 |
Correct |
31 ms |
2284 KB |
n=6666 |
31 |
Correct |
2 ms |
492 KB |
n=4000 |
32 |
Correct |
184 ms |
9964 KB |
n=2857 |
33 |
Correct |
1 ms |
364 KB |
n=2000 |
34 |
Execution timed out |
2089 ms |
329412 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |