Submission #378650

# Submission time Handle Problem Language Result Execution time Memory
378650 2021-03-17T02:46:23 Z abc864197532 Gift (IZhO18_nicegift) C++17
49 / 100
2000 ms 395220 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int, int>
#define pll pair<lli, lli>
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define test(x) cout << #x << ' ' << x << endl
#define printv(x) {\
    for (auto a : x) cout << x << ' ';\
    cout << endl;\
}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const int N = 2000000;

lli a[N];
int n, k;

struct op {
    vector <int> ans;
    lli v;
};

void solve_same() {
    if (accumulate(a, a + n, 0ll) % k != 0) {
        cout << -1 << endl;
        return;
    }
    vector <op> ans;
    lli sum = a[0] / (k / __gcd(n, k));
    for (int i = 0; ans.empty() || i; i = (i + k) % n) {
        vector <int> tmp;
        for (int j = i; j < i + k; ++j) tmp.pb(j % n);
        ans.pb({tmp, sum});
    }
    cout << ans.size() << endl;
    for (op i : ans) {
        cout << i.v << ' ';
        for (int j : i.ans) cout << j + 1 << ' ';
        cout << endl;
    }
}

void solve_count() {
    if (accumulate(a, a + n, 0ll) % k != 0) {
        cout << -1 << endl;
        return;
    }
    priority_queue <pii> pq;
    vector <op> ans;
    for (int i = 0; i < n; ++i) pq.emplace(a[i], i);
    while (pq.size() >= k) {
        vector <int> id;
        while (id.size() < k) {
            id.pb(pq.top().Y); pq.pop();
        }
        for (int i : id) {
            a[i]--;
            if (a[i]) pq.emplace(a[i], i);
        }
        ans.pb({id, 1});
    }
    if (pq.empty()) {
        cout << ans.size() << endl;
        for (op i : ans) {
            cout << i.v << ' ';
            for (int j : i.ans) cout << j + 1 << ' ';
            cout << endl;
        }
    } else {
        cout << -1 << endl;
    }
}

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; ++i) cin >> a[i];
    if (*max_element(a, a + n) == *min_element(a, a + n)) {
        solve_same();
    } else {
        solve_count();
    }
}

Compilation message

nicegift.cpp: In function 'void solve_count()':
nicegift.cpp:56: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]
   56 |     while (pq.size() >= k) {
      |            ~~~~~~~~~~^~~~
nicegift.cpp:58:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   58 |         while (id.size() < k) {
      |                ~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 0 ms 364 KB n=3
3 Correct 0 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 0 ms 364 KB n=3
3 Correct 0 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 3 ms 1132 KB n=8
9 Correct 39 ms 1384 KB n=14
10 Correct 26 ms 1132 KB n=11
11 Correct 161 ms 4964 KB n=50000
12 Correct 144 ms 4964 KB n=50000
13 Correct 136 ms 3936 KB n=10
14 Correct 146 ms 3428 KB n=685
15 Correct 136 ms 3808 KB n=623
16 Correct 70 ms 2276 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 0 ms 364 KB n=3
3 Correct 0 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 3 ms 1132 KB n=8
9 Correct 39 ms 1384 KB n=14
10 Correct 26 ms 1132 KB n=11
11 Correct 161 ms 4964 KB n=50000
12 Correct 144 ms 4964 KB n=50000
13 Correct 136 ms 3936 KB n=10
14 Correct 146 ms 3428 KB n=685
15 Correct 136 ms 3808 KB n=623
16 Correct 70 ms 2276 KB n=973
17 Correct 116 ms 2788 KB n=989
18 Correct 26 ms 1128 KB n=563
19 Correct 28 ms 1384 KB n=592
20 Correct 32 ms 1384 KB n=938
21 Correct 29 ms 1256 KB n=747
22 Correct 29 ms 1256 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 1469 ms 53988 KB n=1000000
2 Correct 718 ms 27612 KB n=666666
3 Correct 304 ms 12376 KB n=400000
4 Correct 965 ms 42596 KB n=285714
5 Correct 7 ms 1004 KB n=20000
6 Correct 706 ms 36632 KB n=181818
7 Correct 4 ms 620 KB n=10000
8 Correct 37 ms 3564 KB n=6666
9 Correct 2 ms 492 KB n=4000
10 Correct 200 ms 17680 KB n=2857
11 Correct 1 ms 364 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 0 ms 364 KB n=3
3 Correct 0 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 3 ms 1132 KB n=8
9 Correct 39 ms 1384 KB n=14
10 Correct 26 ms 1132 KB n=11
11 Correct 161 ms 4964 KB n=50000
12 Correct 144 ms 4964 KB n=50000
13 Correct 136 ms 3936 KB n=10
14 Correct 146 ms 3428 KB n=685
15 Correct 136 ms 3808 KB n=623
16 Correct 70 ms 2276 KB n=973
17 Correct 116 ms 2788 KB n=989
18 Correct 26 ms 1128 KB n=563
19 Correct 28 ms 1384 KB n=592
20 Correct 32 ms 1384 KB n=938
21 Correct 29 ms 1256 KB n=747
22 Correct 29 ms 1256 KB n=991
23 Correct 1469 ms 53988 KB n=1000000
24 Correct 718 ms 27612 KB n=666666
25 Correct 304 ms 12376 KB n=400000
26 Correct 965 ms 42596 KB n=285714
27 Correct 7 ms 1004 KB n=20000
28 Correct 706 ms 36632 KB n=181818
29 Correct 4 ms 620 KB n=10000
30 Correct 37 ms 3564 KB n=6666
31 Correct 2 ms 492 KB n=4000
32 Correct 200 ms 17680 KB n=2857
33 Correct 1 ms 364 KB n=2000
34 Execution timed out 2100 ms 395220 KB Time limit exceeded
35 Halted 0 ms 0 KB -