답안 #587512

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587512 2022-07-02T03:31:30 Z KoD Gift (IZhO18_nicegift) C++17
100 / 100
520 ms 61148 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';
    vector<int> idx(K);
    for (int i = 0; i < Q; ++i) {
        std::cout << split[i + 1] - split[i];
        for (int j = 0; j < K; ++j) {
            while (list[j][idx[j]].first <= split[i]) {
                idx[j] += 1;
            }
            std::cout << ' ' << list[j][idx[j]].second + 1;
        }
        std::cout << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n=4
2 Correct 1 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 1 ms 212 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n=4
2 Correct 1 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 1 ms 212 KB n=2
7 Correct 0 ms 212 KB n=5
8 Correct 1 ms 212 KB n=8
9 Correct 1 ms 212 KB n=14
10 Correct 0 ms 212 KB n=11
11 Correct 15 ms 3020 KB n=50000
12 Correct 16 ms 2640 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n=4
2 Correct 1 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 1 ms 212 KB n=2
7 Correct 0 ms 212 KB n=5
8 Correct 1 ms 212 KB n=8
9 Correct 1 ms 212 KB n=14
10 Correct 0 ms 212 KB n=11
11 Correct 15 ms 3020 KB n=50000
12 Correct 16 ms 2640 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 340 KB n=989
18 Correct 1 ms 324 KB n=563
19 Correct 1 ms 340 KB n=592
20 Correct 2 ms 340 KB n=938
21 Correct 1 ms 324 KB n=747
22 Correct 3 ms 340 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 373 ms 45920 KB n=1000000
2 Correct 195 ms 29216 KB n=666666
3 Correct 120 ms 17008 KB n=400000
4 Correct 249 ms 26708 KB n=285714
5 Correct 6 ms 1316 KB n=20000
6 Correct 214 ms 21624 KB n=181818
7 Correct 5 ms 852 KB n=10000
8 Correct 27 ms 2236 KB n=6666
9 Correct 2 ms 596 KB n=4000
10 Correct 144 ms 9804 KB n=2857
11 Correct 2 ms 468 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n=4
2 Correct 1 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 1 ms 212 KB n=2
7 Correct 0 ms 212 KB n=5
8 Correct 1 ms 212 KB n=8
9 Correct 1 ms 212 KB n=14
10 Correct 0 ms 212 KB n=11
11 Correct 15 ms 3020 KB n=50000
12 Correct 16 ms 2640 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 340 KB n=989
18 Correct 1 ms 324 KB n=563
19 Correct 1 ms 340 KB n=592
20 Correct 2 ms 340 KB n=938
21 Correct 1 ms 324 KB n=747
22 Correct 3 ms 340 KB n=991
23 Correct 373 ms 45920 KB n=1000000
24 Correct 195 ms 29216 KB n=666666
25 Correct 120 ms 17008 KB n=400000
26 Correct 249 ms 26708 KB n=285714
27 Correct 6 ms 1316 KB n=20000
28 Correct 214 ms 21624 KB n=181818
29 Correct 5 ms 852 KB n=10000
30 Correct 27 ms 2236 KB n=6666
31 Correct 2 ms 596 KB n=4000
32 Correct 144 ms 9804 KB n=2857
33 Correct 2 ms 468 KB n=2000
34 Correct 15 ms 1620 KB n=23514
35 Correct 11 ms 1620 KB n=23514
36 Correct 1 ms 316 KB n=940
37 Correct 1 ms 320 KB n=2
38 Correct 61 ms 6836 KB n=100000
39 Correct 73 ms 6944 KB n=100000
40 Correct 0 ms 212 KB n=10
41 Correct 1 ms 340 KB n=100
42 Correct 5 ms 468 KB n=1000
43 Correct 400 ms 61148 KB n=1000000
44 Correct 520 ms 57668 KB n=1000000
45 Correct 360 ms 42864 KB n=666666
46 Correct 284 ms 30884 KB n=400000
47 Correct 147 ms 9492 KB n=2336
48 Correct 254 ms 26748 KB n=285714
49 Correct 210 ms 21604 KB n=181818
50 Correct 165 ms 13608 KB n=40000
51 Correct 155 ms 12024 KB n=20000
52 Correct 146 ms 10552 KB n=10000
53 Correct 147 ms 10408 KB n=6666
54 Correct 141 ms 9884 KB n=4000
55 Correct 163 ms 9784 KB n=2857
56 Correct 139 ms 9168 KB n=2000