# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
57610 |
2018-07-15T12:16:09 Z |
hugo_pm |
Gift (IZhO18_nicegift) |
C++14 |
|
1603 ms |
115736 KB |
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#define int long long
using namespace std;
const int maxVerrous = 1000*1000;
int nbVerrous, tailleOperation;
int reqUnlock[maxVerrous];
int cur[maxVerrous];
priority_queue<pair<int, int>> prq;
signed main()
{
scanf("%lld%lld", &nbVerrous, &tailleOperation);
int som = 0, mx = 0;
for (int indVerrou = 0; indVerrou < nbVerrous; ++indVerrou) {
scanf("%lld", &reqUnlock[indVerrou]);
som += reqUnlock[indVerrou];
mx = max(mx, reqUnlock[indVerrou]);
prq.push({reqUnlock[indVerrou], indVerrou});
}
if (som % tailleOperation != 0 || mx > som / tailleOperation) {
printf("-1\n");
return 0;
}
vector<vector<int>> operations;
operations.reserve(100*1000);
vector<int> curOp(tailleOperation + 1);
int red = som / tailleOperation;
while (! prq.empty()) {
int nbRestants = prq.size();
if (nbRestants < tailleOperation) {
printf("-1\n");
return 0;
}
stack<int> remise;
int x = LLONG_MAX;
for (int indPris = 1; indPris <= tailleOperation; ++indPris) {
auto e = prq.top();
prq.pop();
curOp[indPris] = e.second;
x = min(x, e.first);
remise.push(e.second);
}
if (! prq.empty()) {
x = min(x, red - prq.top().first);
}
curOp[0] = x-1;
red -= x;
operations.push_back(curOp);
while (! remise.empty()) {
int ld = remise.top();
cur[ld] += x;
if (reqUnlock[ld] - cur[ld] != 0) {
prq.push({reqUnlock[ld] - cur[ld], ld});
}
remise.pop();
}
}
printf("%lld\n", (int)(operations.size()));
for (auto op : operations) {
for (int choisi : op) {
printf("%lld ", choisi+1);
}
printf("\n");
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
n=4 |
2 |
Correct |
3 ms |
480 KB |
n=3 |
3 |
Correct |
3 ms |
492 KB |
n=3 |
4 |
Correct |
3 ms |
492 KB |
n=4 |
5 |
Correct |
3 ms |
560 KB |
n=4 |
6 |
Correct |
3 ms |
604 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
n=4 |
2 |
Correct |
3 ms |
480 KB |
n=3 |
3 |
Correct |
3 ms |
492 KB |
n=3 |
4 |
Correct |
3 ms |
492 KB |
n=4 |
5 |
Correct |
3 ms |
560 KB |
n=4 |
6 |
Correct |
3 ms |
604 KB |
n=2 |
7 |
Correct |
3 ms |
604 KB |
n=5 |
8 |
Correct |
2 ms |
604 KB |
n=8 |
9 |
Correct |
2 ms |
604 KB |
n=14 |
10 |
Correct |
3 ms |
604 KB |
n=11 |
11 |
Correct |
37 ms |
4340 KB |
n=50000 |
12 |
Correct |
76 ms |
4340 KB |
n=50000 |
13 |
Correct |
3 ms |
4340 KB |
n=10 |
14 |
Correct |
4 ms |
4340 KB |
n=685 |
15 |
Correct |
3 ms |
4340 KB |
n=623 |
16 |
Correct |
4 ms |
4340 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
n=4 |
2 |
Correct |
3 ms |
480 KB |
n=3 |
3 |
Correct |
3 ms |
492 KB |
n=3 |
4 |
Correct |
3 ms |
492 KB |
n=4 |
5 |
Correct |
3 ms |
560 KB |
n=4 |
6 |
Correct |
3 ms |
604 KB |
n=2 |
7 |
Correct |
3 ms |
604 KB |
n=5 |
8 |
Correct |
2 ms |
604 KB |
n=8 |
9 |
Correct |
2 ms |
604 KB |
n=14 |
10 |
Correct |
3 ms |
604 KB |
n=11 |
11 |
Correct |
37 ms |
4340 KB |
n=50000 |
12 |
Correct |
76 ms |
4340 KB |
n=50000 |
13 |
Correct |
3 ms |
4340 KB |
n=10 |
14 |
Correct |
4 ms |
4340 KB |
n=685 |
15 |
Correct |
3 ms |
4340 KB |
n=623 |
16 |
Correct |
4 ms |
4340 KB |
n=973 |
17 |
Correct |
3 ms |
4340 KB |
n=989 |
18 |
Correct |
3 ms |
4340 KB |
n=563 |
19 |
Correct |
3 ms |
4340 KB |
n=592 |
20 |
Correct |
3 ms |
4340 KB |
n=938 |
21 |
Correct |
3 ms |
4340 KB |
n=747 |
22 |
Correct |
3 ms |
4340 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
875 ms |
73736 KB |
n=1000000 |
2 |
Correct |
593 ms |
73736 KB |
n=666666 |
3 |
Correct |
283 ms |
73736 KB |
n=400000 |
4 |
Correct |
184 ms |
73736 KB |
n=285714 |
5 |
Correct |
15 ms |
73736 KB |
n=20000 |
6 |
Correct |
127 ms |
73736 KB |
n=181818 |
7 |
Correct |
11 ms |
73736 KB |
n=10000 |
8 |
Correct |
7 ms |
73736 KB |
n=6666 |
9 |
Correct |
6 ms |
73736 KB |
n=4000 |
10 |
Correct |
9 ms |
73736 KB |
n=2857 |
11 |
Correct |
4 ms |
73736 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
n=4 |
2 |
Correct |
3 ms |
480 KB |
n=3 |
3 |
Correct |
3 ms |
492 KB |
n=3 |
4 |
Correct |
3 ms |
492 KB |
n=4 |
5 |
Correct |
3 ms |
560 KB |
n=4 |
6 |
Correct |
3 ms |
604 KB |
n=2 |
7 |
Correct |
3 ms |
604 KB |
n=5 |
8 |
Correct |
2 ms |
604 KB |
n=8 |
9 |
Correct |
2 ms |
604 KB |
n=14 |
10 |
Correct |
3 ms |
604 KB |
n=11 |
11 |
Correct |
37 ms |
4340 KB |
n=50000 |
12 |
Correct |
76 ms |
4340 KB |
n=50000 |
13 |
Correct |
3 ms |
4340 KB |
n=10 |
14 |
Correct |
4 ms |
4340 KB |
n=685 |
15 |
Correct |
3 ms |
4340 KB |
n=623 |
16 |
Correct |
4 ms |
4340 KB |
n=973 |
17 |
Correct |
3 ms |
4340 KB |
n=989 |
18 |
Correct |
3 ms |
4340 KB |
n=563 |
19 |
Correct |
3 ms |
4340 KB |
n=592 |
20 |
Correct |
3 ms |
4340 KB |
n=938 |
21 |
Correct |
3 ms |
4340 KB |
n=747 |
22 |
Correct |
3 ms |
4340 KB |
n=991 |
23 |
Correct |
875 ms |
73736 KB |
n=1000000 |
24 |
Correct |
593 ms |
73736 KB |
n=666666 |
25 |
Correct |
283 ms |
73736 KB |
n=400000 |
26 |
Correct |
184 ms |
73736 KB |
n=285714 |
27 |
Correct |
15 ms |
73736 KB |
n=20000 |
28 |
Correct |
127 ms |
73736 KB |
n=181818 |
29 |
Correct |
11 ms |
73736 KB |
n=10000 |
30 |
Correct |
7 ms |
73736 KB |
n=6666 |
31 |
Correct |
6 ms |
73736 KB |
n=4000 |
32 |
Correct |
9 ms |
73736 KB |
n=2857 |
33 |
Correct |
4 ms |
73736 KB |
n=2000 |
34 |
Correct |
25 ms |
73736 KB |
n=23514 |
35 |
Correct |
24 ms |
73736 KB |
n=23514 |
36 |
Correct |
5 ms |
73736 KB |
n=940 |
37 |
Correct |
4 ms |
73736 KB |
n=2 |
38 |
Correct |
65 ms |
73736 KB |
n=100000 |
39 |
Correct |
77 ms |
73736 KB |
n=100000 |
40 |
Correct |
3 ms |
73736 KB |
n=10 |
41 |
Correct |
3 ms |
73736 KB |
n=100 |
42 |
Correct |
7 ms |
73736 KB |
n=1000 |
43 |
Correct |
1376 ms |
99232 KB |
n=1000000 |
44 |
Correct |
1603 ms |
115736 KB |
n=1000000 |
45 |
Correct |
1283 ms |
115736 KB |
n=666666 |
46 |
Correct |
596 ms |
115736 KB |
n=400000 |
47 |
Correct |
18 ms |
115736 KB |
n=2336 |
48 |
Correct |
1000 ms |
115736 KB |
n=285714 |
49 |
Correct |
768 ms |
115736 KB |
n=181818 |
50 |
Correct |
58 ms |
115736 KB |
n=40000 |
51 |
Correct |
24 ms |
115736 KB |
n=20000 |
52 |
Correct |
18 ms |
115736 KB |
n=10000 |
53 |
Correct |
102 ms |
115736 KB |
n=6666 |
54 |
Correct |
10 ms |
115736 KB |
n=4000 |
55 |
Correct |
330 ms |
115736 KB |
n=2857 |
56 |
Correct |
8 ms |
115736 KB |
n=2000 |