답안 #41576

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41576 2018-02-19T12:57:10 Z cheater2k Gift (IZhO18_nicegift) C++14
30 / 100
156 ms 30652 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1000005;

int n, k;
long long a[N];
long long sum;
vector < vector <int> > vres;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i], sum += a[i];
    }
    assert(sum <= 1e5);

    if (sum % k != 0) return printf("-1\n"), 0;

    priority_queue < pair<int,int> > pq;
    for (int i = 1; i <= n; ++i) pq.push(make_pair(a[i], i));

    while(!pq.empty()) {
        int taken = 0;
        vector<int> cur;
        while(!pq.empty() && taken < k) {
            int pos = pq.top().second; pq.pop();
            cur.push_back(pos);
            --a[pos];
            ++taken;
        }

        if (taken != k) return printf("-1\n"), 0;
        for (int pos : cur) {
            if (a[pos]) {
                pq.push(make_pair(a[pos], pos));
            }
        }
        vres.push_back(cur);
    }

    printf("%d\n", vres.size());
    for (auto &v : vres) {
        printf("1 "); // X
        for (int &pos : v) printf("%d ", pos); printf("\n");
    }
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:43:31: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::vector<int> >::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n", vres.size());
                               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB n=4
2 Correct 2 ms 356 KB n=3
3 Correct 2 ms 464 KB n=3
4 Correct 2 ms 572 KB n=4
5 Correct 2 ms 612 KB n=4
6 Correct 2 ms 616 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB n=4
2 Correct 2 ms 356 KB n=3
3 Correct 2 ms 464 KB n=3
4 Correct 2 ms 572 KB n=4
5 Correct 2 ms 612 KB n=4
6 Correct 2 ms 616 KB n=2
7 Correct 2 ms 636 KB n=5
8 Correct 4 ms 1364 KB n=8
9 Correct 9 ms 1680 KB n=14
10 Correct 6 ms 1680 KB n=11
11 Correct 39 ms 5072 KB n=50000
12 Correct 38 ms 5228 KB n=50000
13 Correct 27 ms 5228 KB n=10
14 Correct 29 ms 5228 KB n=685
15 Correct 29 ms 5228 KB n=623
16 Correct 23 ms 5228 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB n=4
2 Correct 2 ms 356 KB n=3
3 Correct 2 ms 464 KB n=3
4 Correct 2 ms 572 KB n=4
5 Correct 2 ms 612 KB n=4
6 Correct 2 ms 616 KB n=2
7 Correct 2 ms 636 KB n=5
8 Correct 4 ms 1364 KB n=8
9 Correct 9 ms 1680 KB n=14
10 Correct 6 ms 1680 KB n=11
11 Correct 39 ms 5072 KB n=50000
12 Correct 38 ms 5228 KB n=50000
13 Correct 27 ms 5228 KB n=10
14 Correct 29 ms 5228 KB n=685
15 Correct 29 ms 5228 KB n=623
16 Correct 23 ms 5228 KB n=973
17 Correct 29 ms 5228 KB n=989
18 Correct 13 ms 5228 KB n=563
19 Correct 20 ms 5228 KB n=592
20 Correct 23 ms 5228 KB n=938
21 Correct 17 ms 5228 KB n=747
22 Correct 18 ms 5228 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Runtime error 156 ms 30652 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB n=4
2 Correct 2 ms 356 KB n=3
3 Correct 2 ms 464 KB n=3
4 Correct 2 ms 572 KB n=4
5 Correct 2 ms 612 KB n=4
6 Correct 2 ms 616 KB n=2
7 Correct 2 ms 636 KB n=5
8 Correct 4 ms 1364 KB n=8
9 Correct 9 ms 1680 KB n=14
10 Correct 6 ms 1680 KB n=11
11 Correct 39 ms 5072 KB n=50000
12 Correct 38 ms 5228 KB n=50000
13 Correct 27 ms 5228 KB n=10
14 Correct 29 ms 5228 KB n=685
15 Correct 29 ms 5228 KB n=623
16 Correct 23 ms 5228 KB n=973
17 Correct 29 ms 5228 KB n=989
18 Correct 13 ms 5228 KB n=563
19 Correct 20 ms 5228 KB n=592
20 Correct 23 ms 5228 KB n=938
21 Correct 17 ms 5228 KB n=747
22 Correct 18 ms 5228 KB n=991
23 Runtime error 156 ms 30652 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Halted 0 ms 0 KB -