Submission #378700

# Submission time Handle Problem Language Result Execution time Memory
378700 2021-03-17T03:22:39 Z balbit Gift (IZhO18_nicegift) C++14
0 / 100
489 ms 30016 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define REP(i,n) for (int i = 0; i<n; ++i)
#define pii pair<int, int>
#define SZ(x) (int)((x).size())
#define ALL(x) x.begin(), x.end()
#define pb push_back

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S && ...y){cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT

const int maxn = 2e6+6;
ll a[maxn];

void GG(){cout<<-1<<endl; exit(0);}
int fr[maxn];

signed main(){
    ios::sync_with_stdio(0), cin.tie(0);
    bug(1,2);
    ll n,k; cin>>n>>k;
    ll sig = 0;
    vector<pair<int, pii> > v;
    ll now = 0, h = 0;
    REP(i,n) {
        cin>>a[i]; sig+=a[i];
    }
    if (sig % k != 0) {
        GG();
    }
    ll gp = sig / k;
    REP(i,n){
        v.pb({now, {h, i}});
        now += a[i];
        bug(now, gp, h);
        if (now >= gp) {
            now -= gp; ++h;
            if (now >= gp) GG();
            if (now) {
                v.pb({0, {h, i}});
            }
        }
    }
    int prv = 0;
    v.pb({gp, {-1, -1}});
    sort(ALL(v));
    for (auto e : v) {
        int df = e.f - prv;
        if (df) {
            cout<<df<<' ';
            REP(i,k) {
                cout<<fr[i]<<' ';
            }
            cout<<'\n';
        }
        if(~e.s.f) {
            fr[e.s.f] = e.s.s+1;

        }
        prv = e.f;
    }


}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 489 ms 30016 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -