답안 #378693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378693 2021-03-17T03:17:06 Z 2qbingxuan Gift (IZhO18_nicegift) C++17
7 / 100
26 ms 5476 KB
#include <bits/stdc++.h>
#ifdef local
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(a...) qqbx(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
    int cnt = sizeof...(T);
    ((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n")));
}
#else
#define safe ((void)0)
#define debug(...) ((void)0)
#endif // local
#define all(v) begin(v),end(v)

using namespace std;
using ll = int64_t;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using max_heap = priority_queue<T, vector<T>, less<T>>;
const int maxn = 100025, inf = 1e9;
const ll INF = 1e18;

ll A[maxn];
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, k;
    cin >> n >> k;
    max_heap<pair<ll,int>> pq;
    for (int i = 1; i <= n; i++) {
        cin >> A[i];
        pq.emplace(A[i], i);
    }
    vector<pair<ll,vector<int>>> ans;
    while (!pq.empty()) {
        vector<int> v;
        ll x = 0;
        for (int t = 0; t < k; t++) {
            if (pq.empty()) return cout << -1 << '\n', 0;
            auto [y, j] = pq.top(); pq.pop();
            v.push_back(j);
            x = y;
        }
        ans.emplace_back(x, v);
        for (int pos: v) {
            A[pos] -= x;
            if (A[pos]) pq.emplace(A[pos], pos);
        }
    }
    cout << ans.size() << '\n';
    for (auto [x, v]: ans) {
        cout << x;
        for (int u: v)
            cout << ' ' << u;
        cout << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 512 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 384 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 512 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 384 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 384 KB n=5
8 Correct 1 ms 364 KB n=8
9 Incorrect 1 ms 364 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 512 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 384 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 384 KB n=5
8 Correct 1 ms 364 KB n=8
9 Incorrect 1 ms 364 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 26 ms 5476 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 512 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 384 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 384 KB n=5
8 Correct 1 ms 364 KB n=8
9 Incorrect 1 ms 364 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -