Submission #44473

# Submission time Handle Problem Language Result Execution time Memory
44473 2018-04-02T09:26:39 Z nickyrio Gift (IZhO18_nicegift) C++17
30 / 100
620 ms 135248 KB
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define DEBUG(x) { cerr << #x << '=' << x << endl; }
#define Arr(a, l, r) { cerr << #a << " = {"; FOR(_, l, r) cerr << ' ' << a[_]; cerr << "}\n"; }
#define N 1001000
#define pp pair<int, int>
#define endl '\n'
#define IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define taskname ""
#define bit(S, i) (((S) >> (i)) & 1)
using namespace std;

int n, k, a[N];
priority_queue<pp> heap;
vector<int> res[N];
int main() {
    #ifdef NERO
    freopen("test.inp","r",stdin);
    freopen("test.out","w",stdout);
    double stime = clock();
    #else 
        //freopen(taskname".inp","r",stdin);
        //freopen(taskname".out","w",stdout);
    #endif //NERO
    IO;
    cin >> n >> k;
    FOR(i, 1, n) {
        cin >> a[i];
        heap.push(pp(a[i], i));
    }
    int cnt = 0;
    while (!heap.empty()) {
        ++cnt;
        if (heap.size() < k) {
            cout << -1;
            return 0;
        }
        REP(i, k) {
            res[cnt].push_back(heap.top().second);
            a[heap.top().second]--;
            heap.pop();
        }
        for (int id : res[cnt]) if (a[id]) heap.push(pp(a[id], id));
    }
    cout << cnt << '\n';
    FOR(i, 1, cnt) {
        cout << "1 ";
        for (int id : res[i]) cout << id << ' ';
        cout << '\n';
    }
    #ifdef NERO
    double etime = clock();
    cerr << "Execution time: " << (etime - stime) / CLOCKS_PER_SEC * 1000 << " ms.\n";
    #endif // NERO
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:36:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (heap.size() < k) {
             ~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 23800 KB n=4
2 Correct 21 ms 24040 KB n=3
3 Correct 25 ms 24040 KB n=3
4 Correct 22 ms 24040 KB n=4
5 Correct 26 ms 24040 KB n=4
6 Correct 25 ms 24040 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 20 ms 23800 KB n=4
2 Correct 21 ms 24040 KB n=3
3 Correct 25 ms 24040 KB n=3
4 Correct 22 ms 24040 KB n=4
5 Correct 26 ms 24040 KB n=4
6 Correct 25 ms 24040 KB n=2
7 Correct 21 ms 24040 KB n=5
8 Correct 22 ms 24348 KB n=8
9 Correct 26 ms 24608 KB n=14
10 Correct 24 ms 24608 KB n=11
11 Correct 57 ms 27272 KB n=50000
12 Correct 53 ms 27324 KB n=50000
13 Correct 42 ms 27324 KB n=10
14 Correct 43 ms 27324 KB n=685
15 Correct 45 ms 27324 KB n=623
16 Correct 35 ms 27324 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 20 ms 23800 KB n=4
2 Correct 21 ms 24040 KB n=3
3 Correct 25 ms 24040 KB n=3
4 Correct 22 ms 24040 KB n=4
5 Correct 26 ms 24040 KB n=4
6 Correct 25 ms 24040 KB n=2
7 Correct 21 ms 24040 KB n=5
8 Correct 22 ms 24348 KB n=8
9 Correct 26 ms 24608 KB n=14
10 Correct 24 ms 24608 KB n=11
11 Correct 57 ms 27272 KB n=50000
12 Correct 53 ms 27324 KB n=50000
13 Correct 42 ms 27324 KB n=10
14 Correct 43 ms 27324 KB n=685
15 Correct 45 ms 27324 KB n=623
16 Correct 35 ms 27324 KB n=973
17 Correct 43 ms 27324 KB n=989
18 Correct 32 ms 27324 KB n=563
19 Correct 40 ms 27324 KB n=592
20 Correct 40 ms 27324 KB n=938
21 Correct 35 ms 27324 KB n=747
22 Correct 38 ms 27324 KB n=991
# Verdict Execution time Memory Grader output
1 Runtime error 620 ms 135248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 23800 KB n=4
2 Correct 21 ms 24040 KB n=3
3 Correct 25 ms 24040 KB n=3
4 Correct 22 ms 24040 KB n=4
5 Correct 26 ms 24040 KB n=4
6 Correct 25 ms 24040 KB n=2
7 Correct 21 ms 24040 KB n=5
8 Correct 22 ms 24348 KB n=8
9 Correct 26 ms 24608 KB n=14
10 Correct 24 ms 24608 KB n=11
11 Correct 57 ms 27272 KB n=50000
12 Correct 53 ms 27324 KB n=50000
13 Correct 42 ms 27324 KB n=10
14 Correct 43 ms 27324 KB n=685
15 Correct 45 ms 27324 KB n=623
16 Correct 35 ms 27324 KB n=973
17 Correct 43 ms 27324 KB n=989
18 Correct 32 ms 27324 KB n=563
19 Correct 40 ms 27324 KB n=592
20 Correct 40 ms 27324 KB n=938
21 Correct 35 ms 27324 KB n=747
22 Correct 38 ms 27324 KB n=991
23 Runtime error 620 ms 135248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Halted 0 ms 0 KB -