Submission #57405

# Submission time Handle Problem Language Result Execution time Memory
57405 2018-07-14T22:21:03 Z hugo_pm Gift (IZhO18_nicegift) C++14
7 / 100
769 ms 56404 KB
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#define len(v) (int)(v.size())
using namespace std;

typedef pair<int, int> pii;
const int maxVerrous = 1000*1000;
int nbVerrous, tailleOperation;
int reqUnlock[maxVerrous];
int cur[maxVerrous];

struct Machin
{
    int req, ind;
    bool operator< (Machin oth) const
    {
        int c1 = reqUnlock[ind] - cur[ind];
        int c2 = reqUnlock[oth.ind] - cur[oth.ind];
        if (c1 != c2) return c1 < c2;
        else return ind < oth.ind;
    }
};

vector<Machin> tab;
set<Machin> wcur;

int main()
{
    scanf("%d%d", &nbVerrous, &tailleOperation);
    tab.resize(nbVerrous);

    for (int indVerrou = 0; indVerrou < nbVerrous; ++indVerrou) {
        scanf("%d", &reqUnlock[indVerrou]);
        tab[indVerrou] = {reqUnlock[indVerrou], indVerrou};
    }

    sort(tab.begin(), tab.end());
    vector<vector<int>> operations;
    operations.reserve(100*1000);
    vector<int> curOp(tailleOperation + 1);

    int indOp = 0;
    while ((! tab.empty()) || (! wcur.empty())) {
        ++indOp;
        if (indOp * tailleOperation > 3*1000*1000 || len(tab) + len(wcur) < tailleOperation) {
            printf("-1\n");
            return 0;
        }

        while (len(wcur) < tailleOperation) {
            wcur.insert(tab.back());
            tab.pop_back();
        }

        auto it = wcur.begin();
        int rem = reqUnlock[it->ind] - cur[it->ind];
        curOp[0] = rem;
        for (int ind = 1; ind <= tailleOperation; ++ind) {
            curOp[ind] = it->ind + 1;
            cur[it->ind] += rem;
            ++it;
        }
        operations.push_back(curOp);
        while ((! wcur.empty()) && (reqUnlock[wcur.begin()->ind] == cur[wcur.begin()->ind])) {
            wcur.erase(wcur.begin());
        }
    }

    printf("%d\n", (int)(operations.size()));
    for (auto op : operations) {
        for (int choisi : op) {
            printf("%d ", choisi);
        }
        printf("\n");
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 3 ms 484 KB n=3
3 Correct 3 ms 484 KB n=3
4 Correct 2 ms 512 KB n=4
5 Correct 2 ms 512 KB n=4
6 Correct 2 ms 616 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 3 ms 484 KB n=3
3 Correct 3 ms 484 KB n=3
4 Correct 2 ms 512 KB n=4
5 Correct 2 ms 512 KB n=4
6 Correct 2 ms 616 KB n=2
7 Correct 2 ms 692 KB n=5
8 Correct 2 ms 692 KB n=8
9 Incorrect 3 ms 692 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 3 ms 484 KB n=3
3 Correct 3 ms 484 KB n=3
4 Correct 2 ms 512 KB n=4
5 Correct 2 ms 512 KB n=4
6 Correct 2 ms 616 KB n=2
7 Correct 2 ms 692 KB n=5
8 Correct 2 ms 692 KB n=8
9 Incorrect 3 ms 692 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 769 ms 56404 KB Added number should be positive
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 3 ms 484 KB n=3
3 Correct 3 ms 484 KB n=3
4 Correct 2 ms 512 KB n=4
5 Correct 2 ms 512 KB n=4
6 Correct 2 ms 616 KB n=2
7 Correct 2 ms 692 KB n=5
8 Correct 2 ms 692 KB n=8
9 Incorrect 3 ms 692 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -