답안 #175581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
175581 2020-01-07T08:24:54 Z juggernaut Gift (IZhO18_nicegift) C++14
100 / 100
768 ms 148312 KB
//Just try and the idea will come
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int n,k,sum,mx,i,a[1000001],mn,sz,res,cnt[1000001],j,tmp;
vector<pair<int,int>>vec[1000001];
vector<int>ans[1000001];
bool flag;
main(){
    scanf("%lld%lld",&n,&k);
    for(i=1;i<=n;i++)scanf("%lld",&a[i]),mx=max(mx,a[i]),sum+=a[i];
    if(sum%k!=0||mx>sum/k){
        puts("-1");
        return 0;
    }
    tmp=0;
    for(i=1;i<=n;i++){
        tmp+=a[i];
        if(tmp>=sum/k){
            vec[sz++].push_back({a[i]-tmp+sum/k,i});
            tmp-=sum/k;
            if(tmp)vec[sz].push_back({tmp,i});
        }else vec[sz].push_back({a[i],i});
    }
    while(!flag){
        mn=1e18;
        for(i=0;i<sz;i++)mn=min(mn,vec[i].back().first);
        cnt[res]=mn;
        flag=0;
        for(i=0;i<sz;i++){
            ans[res].push_back(vec[i].back().second);
            if(vec[i].back().first==mn)vec[i].pop_back();
            else vec[i].back().first-=mn;
            flag|=vec[i].empty();
        }
        res++;
    }
    printf("%lld\n",res);
    for(i=0;i<res;i++){
        printf("%lld",cnt[i]);
        for(j=0;j<k;j++)printf(" %lld",ans[i][j]);
        puts("");
    }
}

Compilation message

nicegift.cpp:9:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
nicegift.cpp: In function 'int main()':
nicegift.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld",&n,&k);
     ~~~~~^~~~~~~~~~~~~~~~~~
nicegift.cpp:11:57: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1;i<=n;i++)scanf("%lld",&a[i]),mx=max(mx,a[i]),sum+=a[i];
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 47324 KB n=4
2 Correct 44 ms 47224 KB n=3
3 Correct 44 ms 47272 KB n=3
4 Correct 44 ms 47352 KB n=4
5 Correct 44 ms 47480 KB n=4
6 Correct 44 ms 47352 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 47324 KB n=4
2 Correct 44 ms 47224 KB n=3
3 Correct 44 ms 47272 KB n=3
4 Correct 44 ms 47352 KB n=4
5 Correct 44 ms 47480 KB n=4
6 Correct 44 ms 47352 KB n=2
7 Correct 42 ms 47352 KB n=5
8 Correct 45 ms 47312 KB n=8
9 Correct 44 ms 47324 KB n=14
10 Correct 46 ms 47272 KB n=11
11 Correct 69 ms 50788 KB n=50000
12 Correct 69 ms 50672 KB n=50000
13 Correct 45 ms 47268 KB n=10
14 Correct 45 ms 47352 KB n=685
15 Correct 45 ms 47332 KB n=623
16 Correct 44 ms 47352 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 47324 KB n=4
2 Correct 44 ms 47224 KB n=3
3 Correct 44 ms 47272 KB n=3
4 Correct 44 ms 47352 KB n=4
5 Correct 44 ms 47480 KB n=4
6 Correct 44 ms 47352 KB n=2
7 Correct 42 ms 47352 KB n=5
8 Correct 45 ms 47312 KB n=8
9 Correct 44 ms 47324 KB n=14
10 Correct 46 ms 47272 KB n=11
11 Correct 69 ms 50788 KB n=50000
12 Correct 69 ms 50672 KB n=50000
13 Correct 45 ms 47268 KB n=10
14 Correct 45 ms 47352 KB n=685
15 Correct 45 ms 47332 KB n=623
16 Correct 44 ms 47352 KB n=973
17 Correct 45 ms 47464 KB n=989
18 Correct 45 ms 47324 KB n=563
19 Correct 46 ms 47564 KB n=592
20 Correct 46 ms 47520 KB n=938
21 Correct 46 ms 47428 KB n=747
22 Correct 47 ms 47480 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 500 ms 118088 KB n=1000000
2 Correct 343 ms 91984 KB n=666666
3 Correct 204 ms 72964 KB n=400000
4 Correct 447 ms 99540 KB n=285714
5 Correct 52 ms 48488 KB n=20000
6 Correct 404 ms 96372 KB n=181818
7 Correct 50 ms 47888 KB n=10000
8 Correct 103 ms 53680 KB n=6666
9 Correct 46 ms 47468 KB n=4000
10 Correct 298 ms 79860 KB n=2857
11 Correct 47 ms 47480 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 47324 KB n=4
2 Correct 44 ms 47224 KB n=3
3 Correct 44 ms 47272 KB n=3
4 Correct 44 ms 47352 KB n=4
5 Correct 44 ms 47480 KB n=4
6 Correct 44 ms 47352 KB n=2
7 Correct 42 ms 47352 KB n=5
8 Correct 45 ms 47312 KB n=8
9 Correct 44 ms 47324 KB n=14
10 Correct 46 ms 47272 KB n=11
11 Correct 69 ms 50788 KB n=50000
12 Correct 69 ms 50672 KB n=50000
13 Correct 45 ms 47268 KB n=10
14 Correct 45 ms 47352 KB n=685
15 Correct 45 ms 47332 KB n=623
16 Correct 44 ms 47352 KB n=973
17 Correct 45 ms 47464 KB n=989
18 Correct 45 ms 47324 KB n=563
19 Correct 46 ms 47564 KB n=592
20 Correct 46 ms 47520 KB n=938
21 Correct 46 ms 47428 KB n=747
22 Correct 47 ms 47480 KB n=991
23 Correct 500 ms 118088 KB n=1000000
24 Correct 343 ms 91984 KB n=666666
25 Correct 204 ms 72964 KB n=400000
26 Correct 447 ms 99540 KB n=285714
27 Correct 52 ms 48488 KB n=20000
28 Correct 404 ms 96372 KB n=181818
29 Correct 50 ms 47888 KB n=10000
30 Correct 103 ms 53680 KB n=6666
31 Correct 46 ms 47468 KB n=4000
32 Correct 298 ms 79860 KB n=2857
33 Correct 47 ms 47480 KB n=2000
34 Correct 60 ms 49272 KB n=23514
35 Correct 55 ms 49392 KB n=23514
36 Correct 46 ms 47380 KB n=940
37 Correct 45 ms 47224 KB n=2
38 Correct 150 ms 61780 KB n=100000
39 Correct 151 ms 61932 KB n=100000
40 Correct 45 ms 47352 KB n=10
41 Correct 45 ms 47332 KB n=100
42 Correct 52 ms 48120 KB n=1000
43 Correct 683 ms 137504 KB n=1000000
44 Correct 768 ms 148312 KB n=1000000
45 Correct 634 ms 129428 KB n=666666
46 Correct 540 ms 114080 KB n=400000
47 Correct 292 ms 75328 KB n=2336
48 Correct 452 ms 99596 KB n=285714
49 Correct 397 ms 96492 KB n=181818
50 Correct 325 ms 81684 KB n=40000
51 Correct 318 ms 79656 KB n=20000
52 Correct 291 ms 78176 KB n=10000
53 Correct 297 ms 84260 KB n=6666
54 Correct 281 ms 73020 KB n=4000
55 Correct 304 ms 79836 KB n=2857
56 Correct 276 ms 71932 KB n=2000