답안 #378681

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378681 2021-03-17T03:09:13 Z 2qbingxuan Gift (IZhO18_nicegift) C++14
0 / 100
22 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>>;
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;
    min_heap<pair<ll,int>> pq;
    for (int i = 1; i <= n; i++) {
        cin >> A[i];
        pq.emplace(A[i], i);
    }
    vector<vector<int>> ans;
    while (!pq.empty()) {
        auto [x, i] = pq.top(); pq.pop();
        vector<int> v;
        v.push_back(i);
        for (int t = 1; t < k; t++) {
            auto [y, j] = pq.top(); pq.pop();
            v.push_back(j);
        }
        debug(v.size());
        ans.push_back(v);
        for (int pos: v) {
            A[pos] -= x;
            if (A[pos]) pq.emplace(A[pos], pos);
        }
    }
    cout << ans.size() << '\n';
    for (auto v: ans) {
        for (int i = 0; i < k; i++)
            cout << v[i] << (i+1==k ? '\n' : ' ');
    }
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:33:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   33 |         auto [x, i] = pq.top(); pq.pop();
      |              ^
nicegift.cpp:37:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   37 |             auto [y, j] = pq.top(); pq.pop();
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 22 ms 5476 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -