답안 #57606

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
57606 2018-07-15T12:13:17 Z hugo_pm Gift (IZhO18_nicegift) C++14
7 / 100
1006 ms 87124 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;
        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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB n=4
2 Correct 3 ms 376 KB n=3
3 Correct 3 ms 404 KB n=3
4 Correct 3 ms 616 KB n=4
5 Correct 2 ms 616 KB n=4
6 Correct 3 ms 616 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB n=4
2 Correct 3 ms 376 KB n=3
3 Correct 3 ms 404 KB n=3
4 Correct 3 ms 616 KB n=4
5 Correct 2 ms 616 KB n=4
6 Correct 3 ms 616 KB n=2
7 Correct 4 ms 616 KB n=5
8 Correct 3 ms 628 KB n=8
9 Incorrect 3 ms 632 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB n=4
2 Correct 3 ms 376 KB n=3
3 Correct 3 ms 404 KB n=3
4 Correct 3 ms 616 KB n=4
5 Correct 2 ms 616 KB n=4
6 Correct 3 ms 616 KB n=2
7 Correct 4 ms 616 KB n=5
8 Correct 3 ms 628 KB n=8
9 Incorrect 3 ms 632 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1006 ms 87124 KB n=1000000
2 Correct 464 ms 87124 KB n=666666
3 Correct 243 ms 87124 KB n=400000
4 Incorrect 151 ms 87124 KB Jury has the answer but participant has not
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB n=4
2 Correct 3 ms 376 KB n=3
3 Correct 3 ms 404 KB n=3
4 Correct 3 ms 616 KB n=4
5 Correct 2 ms 616 KB n=4
6 Correct 3 ms 616 KB n=2
7 Correct 4 ms 616 KB n=5
8 Correct 3 ms 628 KB n=8
9 Incorrect 3 ms 632 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -