Submission #587510

# Submission time Handle Problem Language Result Execution time Memory
587510 2022-07-02T03:14:55 Z KoD Gift (IZhO18_nicegift) C++17
19 / 100
415 ms 59364 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::upper_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 Incorrect 0 ms 212 KB Integer 50 violates the range [1, 3]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n=4
2 Incorrect 0 ms 212 KB Integer 50 violates the range [1, 3]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n=4
2 Incorrect 0 ms 212 KB Integer 50 violates the range [1, 3]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 415 ms 59364 KB n=1000000
2 Correct 240 ms 38148 KB n=666666
3 Correct 129 ms 22384 KB n=400000
4 Correct 304 ms 30332 KB n=285714
5 Correct 6 ms 1364 KB n=20000
6 Correct 264 ms 23844 KB n=181818
7 Correct 3 ms 852 KB n=10000
8 Correct 32 ms 2312 KB n=6666
9 Correct 2 ms 596 KB n=4000
10 Correct 175 ms 9720 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 Incorrect 0 ms 212 KB Integer 50 violates the range [1, 3]
3 Halted 0 ms 0 KB -