답안 #41585

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41585 2018-02-19T14:03:11 Z cheater2k Gift (IZhO18_nicegift) C++14
49 / 100
665 ms 65652 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1000005;

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

int lcm(int x, int y) { // n * k <= 2e6
    int g = __gcd(x, y);
    return x * (y / g);
}

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];
    }
    bool equal = true;
    for (int i = 2; i <= n; ++i) equal &= (a[i] == a[1]);
    
    assert(sum <= 1e5 || equal);
    if (sum % k != 0) return printf("-1\n"), 0;

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

    if (equal) X = sum / lcm(n, k); else X = 1;

    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] -= X;
            ++taken;
        }

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

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

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:53: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 1 ms 248 KB n=4
2 Correct 2 ms 352 KB n=3
3 Correct 1 ms 552 KB n=3
4 Correct 1 ms 556 KB n=4
5 Correct 2 ms 692 KB n=4
6 Correct 1 ms 692 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 248 KB n=4
2 Correct 2 ms 352 KB n=3
3 Correct 1 ms 552 KB n=3
4 Correct 1 ms 556 KB n=4
5 Correct 2 ms 692 KB n=4
6 Correct 1 ms 692 KB n=2
7 Correct 1 ms 692 KB n=5
8 Correct 4 ms 1208 KB n=8
9 Correct 10 ms 1396 KB n=14
10 Correct 6 ms 1396 KB n=11
11 Correct 40 ms 5204 KB n=50000
12 Correct 59 ms 5240 KB n=50000
13 Correct 28 ms 5240 KB n=10
14 Correct 31 ms 5240 KB n=685
15 Correct 45 ms 5240 KB n=623
16 Correct 33 ms 5240 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 248 KB n=4
2 Correct 2 ms 352 KB n=3
3 Correct 1 ms 552 KB n=3
4 Correct 1 ms 556 KB n=4
5 Correct 2 ms 692 KB n=4
6 Correct 1 ms 692 KB n=2
7 Correct 1 ms 692 KB n=5
8 Correct 4 ms 1208 KB n=8
9 Correct 10 ms 1396 KB n=14
10 Correct 6 ms 1396 KB n=11
11 Correct 40 ms 5204 KB n=50000
12 Correct 59 ms 5240 KB n=50000
13 Correct 28 ms 5240 KB n=10
14 Correct 31 ms 5240 KB n=685
15 Correct 45 ms 5240 KB n=623
16 Correct 33 ms 5240 KB n=973
17 Correct 46 ms 5240 KB n=989
18 Correct 15 ms 5240 KB n=563
19 Correct 25 ms 5240 KB n=592
20 Correct 23 ms 5240 KB n=938
21 Correct 19 ms 5240 KB n=747
22 Correct 22 ms 5240 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 616 ms 65652 KB n=1000000
2 Correct 380 ms 65652 KB n=666666
3 Correct 218 ms 65652 KB n=400000
4 Correct 665 ms 65652 KB n=285714
5 Correct 12 ms 65652 KB n=20000
6 Correct 612 ms 65652 KB n=181818
7 Correct 9 ms 65652 KB n=10000
8 Correct 93 ms 65652 KB n=6666
9 Correct 3 ms 65652 KB n=4000
10 Correct 449 ms 65652 KB n=2857
11 Correct 4 ms 65652 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 248 KB n=4
2 Correct 2 ms 352 KB n=3
3 Correct 1 ms 552 KB n=3
4 Correct 1 ms 556 KB n=4
5 Correct 2 ms 692 KB n=4
6 Correct 1 ms 692 KB n=2
7 Correct 1 ms 692 KB n=5
8 Correct 4 ms 1208 KB n=8
9 Correct 10 ms 1396 KB n=14
10 Correct 6 ms 1396 KB n=11
11 Correct 40 ms 5204 KB n=50000
12 Correct 59 ms 5240 KB n=50000
13 Correct 28 ms 5240 KB n=10
14 Correct 31 ms 5240 KB n=685
15 Correct 45 ms 5240 KB n=623
16 Correct 33 ms 5240 KB n=973
17 Correct 46 ms 5240 KB n=989
18 Correct 15 ms 5240 KB n=563
19 Correct 25 ms 5240 KB n=592
20 Correct 23 ms 5240 KB n=938
21 Correct 19 ms 5240 KB n=747
22 Correct 22 ms 5240 KB n=991
23 Correct 616 ms 65652 KB n=1000000
24 Correct 380 ms 65652 KB n=666666
25 Correct 218 ms 65652 KB n=400000
26 Correct 665 ms 65652 KB n=285714
27 Correct 12 ms 65652 KB n=20000
28 Correct 612 ms 65652 KB n=181818
29 Correct 9 ms 65652 KB n=10000
30 Correct 93 ms 65652 KB n=6666
31 Correct 3 ms 65652 KB n=4000
32 Correct 449 ms 65652 KB n=2857
33 Correct 4 ms 65652 KB n=2000
34 Runtime error 4 ms 65652 KB Execution killed with signal 11 (could be triggered by violating memory limits)
35 Halted 0 ms 0 KB -