Submission #587511

# Submission time Handle Problem Language Result Execution time Memory
587511 2022-07-02T03:30:18 Z KoD Gift (IZhO18_nicegift) C++17
100 / 100
577 ms 69784 KB
#include <bits/stdc++.h>

using ll = long long;
using std::vector;
using std::array;
using std::pair;
using std::tuple;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N, K;
    std::cin >> N >> K;
    vector<ll> A(N);
    for (auto& x : A) {
        std::cin >> x;
    }
    const ll sum = std::accumulate(A.begin(), A.end(), 0ll);
    const ll max = *std::max_element(A.begin(), A.end());
    const ll turn = sum / K;
    if (sum % K != 0 or max > turn) {
        std::cout << "-1\n";
        return 0;
    }
    ll cur = 0;
    vector<vector<pair<ll, int>>> list = {{}};
    vector<ll> split = {0, turn};
    split.reserve(N + 2);
    for (int i = 0; i < N; ++i) {
        cur += A[i];
        if (cur >= turn) {
            cur -= turn;
            list.back().emplace_back(turn, i);
            list.emplace_back();
        }
        list.back().emplace_back(cur, i);
        split.push_back(cur);
    }
    std::sort(split.begin(), split.end());
    split.erase(std::unique(split.begin(), split.end()), split.end());
    const int Q = (int)split.size() - 1;
    std::cout << Q << '\n';
    for (int i = 0; i < Q; ++i) {
        std::cout << split[i + 1] - split[i];
        for (int j = 0; j < K; ++j) {
            std::cout << ' ' << std::lower_bound(list[j].begin(), list[j].end(), pair(split[i] + 1, 0))->second + 1;
        }
        std::cout << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 1 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 1 ms 212 KB n=4
6 Correct 1 ms 324 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 1 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 1 ms 212 KB n=4
6 Correct 1 ms 324 KB n=2
7 Correct 1 ms 212 KB n=5
8 Correct 1 ms 212 KB n=8
9 Correct 0 ms 212 KB n=14
10 Correct 1 ms 316 KB n=11
11 Correct 19 ms 3020 KB n=50000
12 Correct 18 ms 2656 KB n=50000
13 Correct 0 ms 212 KB n=10
14 Correct 1 ms 340 KB n=685
15 Correct 1 ms 340 KB n=623
16 Correct 1 ms 340 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 1 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 1 ms 212 KB n=4
6 Correct 1 ms 324 KB n=2
7 Correct 1 ms 212 KB n=5
8 Correct 1 ms 212 KB n=8
9 Correct 0 ms 212 KB n=14
10 Correct 1 ms 316 KB n=11
11 Correct 19 ms 3020 KB n=50000
12 Correct 18 ms 2656 KB n=50000
13 Correct 0 ms 212 KB n=10
14 Correct 1 ms 340 KB n=685
15 Correct 1 ms 340 KB n=623
16 Correct 1 ms 340 KB n=973
17 Correct 1 ms 372 KB n=989
18 Correct 1 ms 316 KB n=563
19 Correct 2 ms 340 KB n=592
20 Correct 2 ms 340 KB n=938
21 Correct 1 ms 316 KB n=747
22 Correct 2 ms 340 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 420 ms 45856 KB n=1000000
2 Correct 224 ms 29100 KB n=666666
3 Correct 129 ms 16920 KB n=400000
4 Correct 294 ms 26580 KB n=285714
5 Correct 6 ms 1108 KB n=20000
6 Correct 278 ms 21464 KB n=181818
7 Correct 3 ms 724 KB n=10000
8 Correct 32 ms 2184 KB n=6666
9 Correct 2 ms 468 KB n=4000
10 Correct 165 ms 9768 KB n=2857
11 Correct 1 ms 468 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 1 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 1 ms 212 KB n=4
6 Correct 1 ms 324 KB n=2
7 Correct 1 ms 212 KB n=5
8 Correct 1 ms 212 KB n=8
9 Correct 0 ms 212 KB n=14
10 Correct 1 ms 316 KB n=11
11 Correct 19 ms 3020 KB n=50000
12 Correct 18 ms 2656 KB n=50000
13 Correct 0 ms 212 KB n=10
14 Correct 1 ms 340 KB n=685
15 Correct 1 ms 340 KB n=623
16 Correct 1 ms 340 KB n=973
17 Correct 1 ms 372 KB n=989
18 Correct 1 ms 316 KB n=563
19 Correct 2 ms 340 KB n=592
20 Correct 2 ms 340 KB n=938
21 Correct 1 ms 316 KB n=747
22 Correct 2 ms 340 KB n=991
23 Correct 420 ms 45856 KB n=1000000
24 Correct 224 ms 29100 KB n=666666
25 Correct 129 ms 16920 KB n=400000
26 Correct 294 ms 26580 KB n=285714
27 Correct 6 ms 1108 KB n=20000
28 Correct 278 ms 21464 KB n=181818
29 Correct 3 ms 724 KB n=10000
30 Correct 32 ms 2184 KB n=6666
31 Correct 2 ms 468 KB n=4000
32 Correct 165 ms 9768 KB n=2857
33 Correct 1 ms 468 KB n=2000
34 Correct 14 ms 1648 KB n=23514
35 Correct 11 ms 1692 KB n=23514
36 Correct 1 ms 320 KB n=940
37 Correct 1 ms 320 KB n=2
38 Correct 74 ms 7116 KB n=100000
39 Correct 74 ms 7152 KB n=100000
40 Correct 1 ms 212 KB n=10
41 Correct 1 ms 316 KB n=100
42 Correct 5 ms 468 KB n=1000
43 Correct 540 ms 67220 KB n=1000000
44 Correct 577 ms 69784 KB n=1000000
45 Correct 407 ms 51204 KB n=666666
46 Correct 320 ms 36000 KB n=400000
47 Correct 173 ms 9520 KB n=2336
48 Correct 304 ms 30276 KB n=285714
49 Correct 273 ms 23788 KB n=181818
50 Correct 195 ms 14028 KB n=40000
51 Correct 186 ms 12360 KB n=20000
52 Correct 174 ms 10700 KB n=10000
53 Correct 176 ms 10452 KB n=6666
54 Correct 189 ms 9980 KB n=4000
55 Correct 177 ms 9748 KB n=2857
56 Correct 161 ms 9164 KB n=2000