제출 #44473

#제출 시각아이디문제언어결과실행 시간메모리
44473nickyrioGift (IZhO18_nicegift)C++17
30 / 100
620 ms135248 KiB
#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
}

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...