답안 #378607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378607 2021-03-17T02:13:07 Z joylintp Gift (IZhO18_nicegift) C++17
7 / 100
585 ms 48596 KB
#include<bits/stdc++.h>
using namespace std;

//#pragma gcc optimize("Ofast,unroll-loops")
//#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
//#define int long long
//#define double long double
#define MP make_pair
#define F first
#define S second
#define MOD 1000000007

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int N, K;
    cin >> N >> K;

    int A;
    priority_queue<pair<int, int>> pq;
    for (int i = 1; i <= N; i++)
        cin >> A, pq.push(MP(A, i));

    vector<vector<int>> ans;
    while (pq.size() >= K)
    {
        ans.push_back({});

        vector<pair<int, int>> v;
        for (int i = 0; i < K; i++)
            ans.back().push_back(pq.top().S), v.push_back(pq.top()), pq.pop();
        ans.back().push_back(v.back().F), swap(ans.back()[0], ans.back().back());

        for (auto &p : v)
        {
            p.F -= v.back().F;
            if (p.F)
                pq.push(p);
        }
    }

    if (pq.empty())
    {
        cout << ans.size() << '\n';
        for (auto v : ans)
        {
            for (int i : v)
                cout << i << ' ';
            cout << '\n';
        }
    }
    else
        cout << "-1\n";

    return 0;
}

//      *   *  *****  *   *  *   *   ****  ****    ****     **    **
//     *   *  *      **  *  *   *  *      *   *  *        * *   * *
//    *****  *****  * * *  *   *  *      ****   *       *  *     *
//   *   *      *  *  **  *   *  *      *  *   *       *****    *
//  *   *  *****  *   *   ***    ****  *   *    ****     *   *****

//      *****  *****  *   *  *      *****  *   *  *****  *****
//        *   *   *  *   *  *        *    **  *    *    *   *
//       *   *   *  *****  *        *    * * *    *    *****
//   *  *   *   *    *    *        *    *  **    *    *
//  ****   *****    *    *****  *****  *   *    *    *

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:27:22: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |     while (pq.size() >= K)
      |            ~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 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 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 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 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 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 Incorrect 585 ms 48596 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 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 -