답안 #378707

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378707 2021-03-17T03:26:46 Z balbit Gift (IZhO18_nicegift) C++14
100 / 100
709 ms 59812 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define int ll
#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];
        if (a[i] > gp) GG();
        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));
    int fofo = 0;
    REP(i,SZ(v)) {
        if (v[i].f != prv) ++fofo;
        prv = v[i].f;
    }
    cout<<fofo<<endl;
    prv = 0;
    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;
    }


}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 512 KB n=4
5 Correct 1 ms 512 KB n=4
6 Correct 1 ms 364 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 512 KB n=4
5 Correct 1 ms 512 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 0 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 22 ms 2656 KB n=50000
12 Correct 21 ms 2656 KB n=50000
13 Correct 1 ms 364 KB n=10
14 Correct 1 ms 364 KB n=685
15 Correct 1 ms 364 KB n=623
16 Correct 1 ms 384 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 512 KB n=4
5 Correct 1 ms 512 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 0 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 22 ms 2656 KB n=50000
12 Correct 21 ms 2656 KB n=50000
13 Correct 1 ms 364 KB n=10
14 Correct 1 ms 364 KB n=685
15 Correct 1 ms 364 KB n=623
16 Correct 1 ms 384 KB n=973
17 Correct 1 ms 364 KB n=989
18 Correct 1 ms 364 KB n=563
19 Correct 2 ms 492 KB n=592
20 Correct 2 ms 492 KB n=938
21 Correct 1 ms 492 KB n=747
22 Correct 2 ms 492 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 539 ms 46372 KB n=1000000
2 Correct 273 ms 30292 KB n=666666
3 Correct 163 ms 17088 KB n=400000
4 Correct 311 ms 26944 KB n=285714
5 Correct 8 ms 1384 KB n=20000
6 Correct 269 ms 21584 KB n=181818
7 Correct 5 ms 940 KB n=10000
8 Correct 31 ms 2348 KB n=6666
9 Correct 2 ms 620 KB n=4000
10 Correct 172 ms 9964 KB n=2857
11 Correct 1 ms 492 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 512 KB n=4
5 Correct 1 ms 512 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 0 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 22 ms 2656 KB n=50000
12 Correct 21 ms 2656 KB n=50000
13 Correct 1 ms 364 KB n=10
14 Correct 1 ms 364 KB n=685
15 Correct 1 ms 364 KB n=623
16 Correct 1 ms 384 KB n=973
17 Correct 1 ms 364 KB n=989
18 Correct 1 ms 364 KB n=563
19 Correct 2 ms 492 KB n=592
20 Correct 2 ms 492 KB n=938
21 Correct 1 ms 492 KB n=747
22 Correct 2 ms 492 KB n=991
23 Correct 539 ms 46372 KB n=1000000
24 Correct 273 ms 30292 KB n=666666
25 Correct 163 ms 17088 KB n=400000
26 Correct 311 ms 26944 KB n=285714
27 Correct 8 ms 1384 KB n=20000
28 Correct 269 ms 21584 KB n=181818
29 Correct 5 ms 940 KB n=10000
30 Correct 31 ms 2348 KB n=6666
31 Correct 2 ms 620 KB n=4000
32 Correct 172 ms 9964 KB n=2857
33 Correct 1 ms 492 KB n=2000
34 Correct 13 ms 1764 KB n=23514
35 Correct 13 ms 1764 KB n=23514
36 Correct 1 ms 364 KB n=940
37 Correct 1 ms 364 KB n=2
38 Correct 74 ms 7260 KB n=100000
39 Correct 75 ms 7260 KB n=100000
40 Correct 1 ms 364 KB n=10
41 Correct 1 ms 364 KB n=100
42 Correct 5 ms 620 KB n=1000
43 Correct 508 ms 56228 KB n=1000000
44 Correct 709 ms 59812 KB n=1000000
45 Correct 462 ms 45348 KB n=666666
46 Correct 356 ms 33856 KB n=400000
47 Correct 173 ms 9708 KB n=2336
48 Correct 308 ms 29888 KB n=285714
49 Correct 269 ms 24016 KB n=181818
50 Correct 202 ms 14048 KB n=40000
51 Correct 205 ms 12516 KB n=20000
52 Correct 177 ms 10984 KB n=10000
53 Correct 176 ms 10540 KB n=6666
54 Correct 176 ms 10156 KB n=4000
55 Correct 192 ms 9964 KB n=2857
56 Correct 171 ms 9452 KB n=2000