Submission #706707

# Submission time Handle Problem Language Result Execution time Memory
706707 2023-03-07T12:42:50 Z LittleCube Gift (IZhO18_nicegift) C++14
0 / 100
48 ms 3444 KB
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

ll N, K, A[100006], sum, acc[100006], id[100006];
vector<pair<ll, pll>> v;
vector<ll> t;

signed main()
{
    cin >> N >> K;
    for (int i = 1; i <= N; i++)
    {
        cin >> A[i];
        sum += A[i];
    }
    if (sum % K)
    {
        cout << -1 << '\n';
        return 0;
    }
    for (int i = 1; i <= N; i++)
        if (A[i] > sum / K)
        {
            cout << -1 << '\n';
            return 0;
        }
    int cur = 1;
    for (int i = 1; i <= N; i++)
    {
        if (A[i] > sum / K - acc[cur])
        {
            v.emplace_back(make_pair(acc[cur], pll(cur, i)));
            A[i] -= sum / K - acc[cur];
            cur++;
        }
        v.emplace_back(make_pair(acc[cur], pll(cur, i)));
        acc[cur] += A[i];
    }
    for (auto [a, p] : v)
        t.emplace_back(a);
    sort(v.begin(), v.end());
    sort(t.begin(), t.end());
    t.resize(unique(t.begin(), t.end()) - t.begin());

    cout << t.size() - 1 << '\n';
    int vdx = 0;
    for (int i = 1; i < t.size(); i++)
    {
        cout << t[i] - t[i - 1];
        while (vdx < v.size() && v[vdx].F <= t[i - 1])
        {
            id[v[vdx].S.F] = v[vdx].S.S;
            vdx++;
        }
        for (int i = 1; i <= K; i++)
            cout << ' ' << id[i];
        cout << '\n';
    }
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:43:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   43 |     for (auto [a, p] : v)
      |               ^
nicegift.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for (int i = 1; i < t.size(); i++)
      |                     ~~^~~~~~~~~~
nicegift.cpp:54:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         while (vdx < v.size() && v[vdx].F <= t[i - 1])
      |                ~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Incorrect 1 ms 216 KB Not all heaps are empty in the end
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Incorrect 1 ms 216 KB Not all heaps are empty in the end
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Incorrect 1 ms 216 KB Not all heaps are empty in the end
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 48 ms 3444 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Incorrect 1 ms 216 KB Not all heaps are empty in the end
5 Halted 0 ms 0 KB -