답안 #893261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
893261 2023-12-26T18:47:39 Z vjudge1 Gift (IZhO18_nicegift) C++17
100 / 100
728 ms 98112 KB
// 以上帝的名义
// 候选硕士
#include <bits/stdc++.h>

#ifdef local
#include "algo/debug.h"
#else
#define dbg(x...) 0
#endif

using namespace std ;
using ll = long long ;

#define int ll

int32_t main() {
    cin.tie(0)->sync_with_stdio(false) ;
    ll n , k ; cin >> n >> k ;
    vector<ll> a(n) ;
    for (ll &i : a) cin >> i ;
    priority_queue<pair<ll,ll>> q ;
    for (int i = 0 ; i < n ; i++) {
        q.push({a[i], i}) ;
    }
    ll sum = 0 ;
    for (ll i : a) sum += i ;
    if (sum % k) {
        cout << -1 ;
        return 0 ;
    }
    if (sum / k < q.top().first) {
        cout << -1 ;
        return 0 ;
    }
    vector<vector<ll>> res ;
    while (q.size() >= k) {
        deque<ll> cur ;
        ll mn = INT_MAX ;
        for (int i = 0 ; i < k ; i++) {
            auto [value, ind] = q.top() ;
            q.pop() ;
            cur.push_back(ind) ;
            mn = value ;
        }
        if (q.size())
            mn = min(mn * 1ll, (sum / k) - q.top().first) ;
        sum -= k * mn ;
        vector<ll> vec ;
        vec.push_back(mn) ;
        for (ll& i : cur) {
            a[i] -= mn ;
            vec.push_back(i + 1) ;
            if (a[i]> 0) {
                q.push({a[i], i}) ;
            }
        }
        res.push_back(vec) ;
    }
    if (sum) {
        cout << -1 ;
        return 0 ;
    }
    reverse(res.begin(), res.end()) ;
    cout << (ll)res.size() << "\n" ;
    if (res.size()) {
        for (auto i : res) {
            for (auto x : i) {
                cout << x << ' ' ;
            }
            cout << "\n" ;
        }
    }
    return 0 ;
}

// 希望白银

Compilation message

nicegift.cpp: In function 'int32_t main()':
nicegift.cpp:36: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]
   36 |     while (q.size() >= k) {
      |            ~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 344 KB n=3
4 Correct 1 ms 344 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 344 KB n=3
4 Correct 1 ms 344 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 0 ms 348 KB n=5
8 Correct 0 ms 348 KB n=8
9 Correct 0 ms 348 KB n=14
10 Correct 0 ms 348 KB n=11
11 Correct 18 ms 3888 KB n=50000
12 Correct 15 ms 3380 KB n=50000
13 Correct 0 ms 344 KB n=10
14 Correct 0 ms 344 KB n=685
15 Correct 1 ms 348 KB n=623
16 Correct 1 ms 348 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 344 KB n=3
4 Correct 1 ms 344 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 0 ms 348 KB n=5
8 Correct 0 ms 348 KB n=8
9 Correct 0 ms 348 KB n=14
10 Correct 0 ms 348 KB n=11
11 Correct 18 ms 3888 KB n=50000
12 Correct 15 ms 3380 KB n=50000
13 Correct 0 ms 344 KB n=10
14 Correct 0 ms 344 KB n=685
15 Correct 1 ms 348 KB n=623
16 Correct 1 ms 348 KB n=973
17 Correct 1 ms 600 KB n=989
18 Correct 0 ms 348 KB n=563
19 Correct 1 ms 348 KB n=592
20 Correct 1 ms 348 KB n=938
21 Correct 1 ms 348 KB n=747
22 Correct 1 ms 348 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 372 ms 65716 KB n=1000000
2 Correct 229 ms 41124 KB n=666666
3 Correct 124 ms 21556 KB n=400000
4 Correct 84 ms 14008 KB n=285714
5 Correct 5 ms 1248 KB n=20000
6 Correct 51 ms 8652 KB n=181818
7 Correct 3 ms 856 KB n=10000
8 Correct 2 ms 604 KB n=6666
9 Correct 1 ms 604 KB n=4000
10 Correct 3 ms 604 KB n=2857
11 Correct 1 ms 344 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 344 KB n=3
4 Correct 1 ms 344 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 0 ms 348 KB n=5
8 Correct 0 ms 348 KB n=8
9 Correct 0 ms 348 KB n=14
10 Correct 0 ms 348 KB n=11
11 Correct 18 ms 3888 KB n=50000
12 Correct 15 ms 3380 KB n=50000
13 Correct 0 ms 344 KB n=10
14 Correct 0 ms 344 KB n=685
15 Correct 1 ms 348 KB n=623
16 Correct 1 ms 348 KB n=973
17 Correct 1 ms 600 KB n=989
18 Correct 0 ms 348 KB n=563
19 Correct 1 ms 348 KB n=592
20 Correct 1 ms 348 KB n=938
21 Correct 1 ms 348 KB n=747
22 Correct 1 ms 348 KB n=991
23 Correct 372 ms 65716 KB n=1000000
24 Correct 229 ms 41124 KB n=666666
25 Correct 124 ms 21556 KB n=400000
26 Correct 84 ms 14008 KB n=285714
27 Correct 5 ms 1248 KB n=20000
28 Correct 51 ms 8652 KB n=181818
29 Correct 3 ms 856 KB n=10000
30 Correct 2 ms 604 KB n=6666
31 Correct 1 ms 604 KB n=4000
32 Correct 3 ms 604 KB n=2857
33 Correct 1 ms 344 KB n=2000
34 Correct 12 ms 2268 KB n=23514
35 Correct 12 ms 2268 KB n=23514
36 Correct 1 ms 348 KB n=940
37 Correct 0 ms 348 KB n=2
38 Correct 31 ms 5212 KB n=100000
39 Correct 31 ms 5328 KB n=100000
40 Correct 0 ms 348 KB n=10
41 Correct 0 ms 348 KB n=100
42 Correct 2 ms 604 KB n=1000
43 Correct 475 ms 88400 KB n=1000000
44 Correct 728 ms 98112 KB n=1000000
45 Correct 433 ms 67336 KB n=666666
46 Correct 239 ms 38076 KB n=400000
47 Correct 8 ms 1116 KB n=2336
48 Correct 446 ms 57012 KB n=285714
49 Correct 386 ms 47888 KB n=181818
50 Correct 20 ms 3020 KB n=40000
51 Correct 10 ms 1756 KB n=20000
52 Correct 6 ms 980 KB n=10000
53 Correct 45 ms 4560 KB n=6666
54 Correct 3 ms 604 KB n=4000
55 Correct 166 ms 16176 KB n=2857
56 Correct 2 ms 472 KB n=2000