답안 #308753

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308753 2020-10-01T20:52:05 Z aZvezda Gift (IZhO18_nicegift) C++14
100 / 100
1138 ms 100684 KB
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e18 + 7;
template<class T> inline void fix(T &x) {if(labs(x) >= mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    vector<vector<ll> > ans;
    ll n, k;
    cin >> n >> k;
    priority_queue<pair<ll, ll> > pq;
    ll avr = 0;
    for(ll i = 0; i < n; i ++) {
        ll a;
        cin >> a;
        avr += a;
        if(a != 0) {
            pq.push({a, i});
        }
    }
    if(avr % k != 0) {
        cout << -1 << endl;
        return 0;
    }
    while(pq.size() >= k) {
        vector<pair<ll, ll> > curr;
        ll get = mod;
        for(ll i = 0; i < k; i ++) {
            chkmin(get, pq.top().first);
            curr.push_back(pq.top()); pq.pop();
        }
        if(!pq.empty()) {
            chkmin(get, avr / k - pq.top().first);
        }
        ans.resize(ans.size() + 1);
        ans.back().push_back(get);
        avr -= k * get;
        for(auto &it : curr) {
            ans.back().push_back(it.second + 1);
            it.first -= get;
            if(it.first > 0) {
                pq.push({it});
            }
        }
    }
    if(pq.size() != 0) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans.size() << endl;
    for(auto it : ans) {
        for(auto itt : it) {
            cout << itt << " ";
        }
        cout << endl;
    }
    return 0;
}


Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:34:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   34 |     while(pq.size() >= k) {
      |           ~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 0 ms 384 KB n=3
3 Correct 0 ms 384 KB n=3
4 Correct 0 ms 384 KB n=4
5 Correct 0 ms 384 KB n=4
6 Correct 0 ms 384 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 0 ms 384 KB n=3
3 Correct 0 ms 384 KB n=3
4 Correct 0 ms 384 KB n=4
5 Correct 0 ms 384 KB n=4
6 Correct 0 ms 384 KB n=2
7 Correct 0 ms 384 KB n=5
8 Correct 0 ms 384 KB n=8
9 Correct 0 ms 384 KB n=14
10 Correct 1 ms 384 KB n=11
11 Correct 29 ms 3832 KB n=50000
12 Correct 25 ms 3440 KB n=50000
13 Correct 0 ms 384 KB n=10
14 Correct 1 ms 384 KB n=685
15 Correct 1 ms 384 KB n=623
16 Correct 1 ms 384 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 0 ms 384 KB n=3
3 Correct 0 ms 384 KB n=3
4 Correct 0 ms 384 KB n=4
5 Correct 0 ms 384 KB n=4
6 Correct 0 ms 384 KB n=2
7 Correct 0 ms 384 KB n=5
8 Correct 0 ms 384 KB n=8
9 Correct 0 ms 384 KB n=14
10 Correct 1 ms 384 KB n=11
11 Correct 29 ms 3832 KB n=50000
12 Correct 25 ms 3440 KB n=50000
13 Correct 0 ms 384 KB n=10
14 Correct 1 ms 384 KB n=685
15 Correct 1 ms 384 KB n=623
16 Correct 1 ms 384 KB n=973
17 Correct 1 ms 384 KB n=989
18 Correct 1 ms 384 KB n=563
19 Correct 1 ms 384 KB n=592
20 Correct 1 ms 384 KB n=938
21 Correct 1 ms 384 KB n=747
22 Correct 1 ms 384 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 624 ms 65984 KB n=1000000
2 Correct 391 ms 34412 KB n=666666
3 Correct 219 ms 19924 KB n=400000
4 Correct 146 ms 11988 KB n=285714
5 Correct 9 ms 1280 KB n=20000
6 Correct 87 ms 10208 KB n=181818
7 Correct 4 ms 896 KB n=10000
8 Correct 4 ms 760 KB n=6666
9 Correct 2 ms 512 KB n=4000
10 Correct 4 ms 768 KB n=2857
11 Correct 1 ms 512 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 0 ms 384 KB n=3
3 Correct 0 ms 384 KB n=3
4 Correct 0 ms 384 KB n=4
5 Correct 0 ms 384 KB n=4
6 Correct 0 ms 384 KB n=2
7 Correct 0 ms 384 KB n=5
8 Correct 0 ms 384 KB n=8
9 Correct 0 ms 384 KB n=14
10 Correct 1 ms 384 KB n=11
11 Correct 29 ms 3832 KB n=50000
12 Correct 25 ms 3440 KB n=50000
13 Correct 0 ms 384 KB n=10
14 Correct 1 ms 384 KB n=685
15 Correct 1 ms 384 KB n=623
16 Correct 1 ms 384 KB n=973
17 Correct 1 ms 384 KB n=989
18 Correct 1 ms 384 KB n=563
19 Correct 1 ms 384 KB n=592
20 Correct 1 ms 384 KB n=938
21 Correct 1 ms 384 KB n=747
22 Correct 1 ms 384 KB n=991
23 Correct 624 ms 65984 KB n=1000000
24 Correct 391 ms 34412 KB n=666666
25 Correct 219 ms 19924 KB n=400000
26 Correct 146 ms 11988 KB n=285714
27 Correct 9 ms 1280 KB n=20000
28 Correct 87 ms 10208 KB n=181818
29 Correct 4 ms 896 KB n=10000
30 Correct 4 ms 760 KB n=6666
31 Correct 2 ms 512 KB n=4000
32 Correct 4 ms 768 KB n=2857
33 Correct 1 ms 512 KB n=2000
34 Correct 19 ms 2428 KB n=23514
35 Correct 18 ms 2428 KB n=23514
36 Correct 1 ms 384 KB n=940
37 Correct 0 ms 384 KB n=2
38 Correct 52 ms 5224 KB n=100000
39 Correct 53 ms 5356 KB n=100000
40 Correct 1 ms 384 KB n=10
41 Correct 1 ms 384 KB n=100
42 Correct 3 ms 512 KB n=1000
43 Correct 769 ms 90776 KB n=1000000
44 Correct 1138 ms 100684 KB n=1000000
45 Correct 732 ms 58688 KB n=666666
46 Correct 431 ms 37076 KB n=400000
47 Correct 11 ms 1152 KB n=2336
48 Correct 780 ms 57316 KB n=285714
49 Correct 667 ms 49620 KB n=181818
50 Correct 30 ms 2936 KB n=40000
51 Correct 14 ms 1660 KB n=20000
52 Correct 9 ms 1152 KB n=10000
53 Correct 60 ms 6008 KB n=6666
54 Correct 5 ms 640 KB n=4000
55 Correct 235 ms 20984 KB n=2857
56 Correct 3 ms 640 KB n=2000