답안 #170875

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
170875 2019-12-26T16:09:27 Z emil_physmath Gift (IZhO18_nicegift) C++17
7 / 100
1587 ms 130388 KB
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
using namespace std;
typedef double ldouble;
typedef long long llong;
const int maxN = 100001;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<llong> arr(n);
    multiset<pair<llong, int>> a;
    llong mx = -1, sum = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> arr[i];
        sum += arr[i];
        mx = max(mx, arr[i]);
        a.insert({arr[i], i});
    }
    if (sum % k || mx > sum / k)
    {
        cout << -1 << endl;
        exit(0);
    }
    vector<pair<llong, vector<int>>> ans;
    while (a.rbegin()->first)
    {
        vector<int> cur;
        llong mn = a.rbegin()->first;
        for (auto it = a.rbegin(); it != a.rend() && cur.size() < k; ++it)
        {
            cur.push_back(it->second);
            mn = min(mn, it->first);
        }
        if (cur.size() < k || !mn)
        {
            throw;
            cout << -1 << endl;
            exit(0);
        }
        for (int x: cur)
        {
            a.erase({arr[x], x});
            a.insert({arr[x] -= mn, x});
        }
        ans.push_back({mn, cur});
        /*cerr << "a` ";
        for (pair<llong, int> i: a)
            cerr << i.first << ' ';
        cerr << endl;*/
    }
    cout << ans.size() << '\n';
    for (auto x: ans)
    {
        cout << x.first << ' ';
        for (int y: x.second)
            cout << y + 1 << ' ';
        cout << '\n';
    }
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:40:65: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (auto it = a.rbegin(); it != a.rend() && cur.size() < k; ++it)
                                                      ~~~~~~~~~~~^~~
nicegift.cpp:45:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (cur.size() < k || !mn)
             ~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 380 KB n=4
6 Correct 2 ms 376 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 380 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 380 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1587 ms 130388 KB n=1000000
2 Correct 959 ms 78660 KB n=666666
3 Correct 570 ms 43180 KB n=400000
4 Runtime error 353 ms 51636 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 380 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Halted 0 ms 0 KB -