Submission #175589

# Submission time Handle Problem Language Result Execution time Memory
175589 2020-01-07T08:27:09 Z juggernaut Gift (IZhO18_nicegift) C++14
100 / 100
759 ms 134876 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();
        }
        if(flag)for(i=0;i<sz;i++)if(!vec[i].empty())runtime_error(0);
        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];
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 46 ms 47224 KB n=4
2 Correct 47 ms 47224 KB n=3
3 Correct 46 ms 47352 KB n=3
4 Correct 47 ms 47328 KB n=4
5 Correct 46 ms 47224 KB n=4
6 Correct 46 ms 47356 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 46 ms 47224 KB n=4
2 Correct 47 ms 47224 KB n=3
3 Correct 46 ms 47352 KB n=3
4 Correct 47 ms 47328 KB n=4
5 Correct 46 ms 47224 KB n=4
6 Correct 46 ms 47356 KB n=2
7 Correct 46 ms 47324 KB n=5
8 Correct 46 ms 47224 KB n=8
9 Correct 47 ms 47224 KB n=14
10 Correct 46 ms 47224 KB n=11
11 Correct 72 ms 50768 KB n=50000
12 Correct 71 ms 50544 KB n=50000
13 Correct 46 ms 47224 KB n=10
14 Correct 47 ms 47356 KB n=685
15 Correct 47 ms 47352 KB n=623
16 Correct 47 ms 47352 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 46 ms 47224 KB n=4
2 Correct 47 ms 47224 KB n=3
3 Correct 46 ms 47352 KB n=3
4 Correct 47 ms 47328 KB n=4
5 Correct 46 ms 47224 KB n=4
6 Correct 46 ms 47356 KB n=2
7 Correct 46 ms 47324 KB n=5
8 Correct 46 ms 47224 KB n=8
9 Correct 47 ms 47224 KB n=14
10 Correct 46 ms 47224 KB n=11
11 Correct 72 ms 50768 KB n=50000
12 Correct 71 ms 50544 KB n=50000
13 Correct 46 ms 47224 KB n=10
14 Correct 47 ms 47356 KB n=685
15 Correct 47 ms 47352 KB n=623
16 Correct 47 ms 47352 KB n=973
17 Correct 47 ms 47344 KB n=989
18 Correct 51 ms 47376 KB n=563
19 Correct 47 ms 47480 KB n=592
20 Correct 49 ms 47484 KB n=938
21 Correct 49 ms 47480 KB n=747
22 Correct 48 ms 47480 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 491 ms 104392 KB n=1000000
2 Correct 327 ms 82908 KB n=666666
3 Correct 204 ms 67464 KB n=400000
4 Correct 446 ms 95720 KB n=285714
5 Correct 56 ms 48388 KB n=20000
6 Correct 403 ms 94024 KB n=181818
7 Correct 48 ms 47736 KB n=10000
8 Correct 82 ms 53700 KB n=6666
9 Correct 59 ms 47516 KB n=4000
10 Correct 294 ms 79768 KB n=2857
11 Correct 46 ms 47396 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 46 ms 47224 KB n=4
2 Correct 47 ms 47224 KB n=3
3 Correct 46 ms 47352 KB n=3
4 Correct 47 ms 47328 KB n=4
5 Correct 46 ms 47224 KB n=4
6 Correct 46 ms 47356 KB n=2
7 Correct 46 ms 47324 KB n=5
8 Correct 46 ms 47224 KB n=8
9 Correct 47 ms 47224 KB n=14
10 Correct 46 ms 47224 KB n=11
11 Correct 72 ms 50768 KB n=50000
12 Correct 71 ms 50544 KB n=50000
13 Correct 46 ms 47224 KB n=10
14 Correct 47 ms 47356 KB n=685
15 Correct 47 ms 47352 KB n=623
16 Correct 47 ms 47352 KB n=973
17 Correct 47 ms 47344 KB n=989
18 Correct 51 ms 47376 KB n=563
19 Correct 47 ms 47480 KB n=592
20 Correct 49 ms 47484 KB n=938
21 Correct 49 ms 47480 KB n=747
22 Correct 48 ms 47480 KB n=991
23 Correct 491 ms 104392 KB n=1000000
24 Correct 327 ms 82908 KB n=666666
25 Correct 204 ms 67464 KB n=400000
26 Correct 446 ms 95720 KB n=285714
27 Correct 56 ms 48388 KB n=20000
28 Correct 403 ms 94024 KB n=181818
29 Correct 48 ms 47736 KB n=10000
30 Correct 82 ms 53700 KB n=6666
31 Correct 59 ms 47516 KB n=4000
32 Correct 294 ms 79768 KB n=2857
33 Correct 46 ms 47396 KB n=2000
34 Correct 59 ms 49204 KB n=23514
35 Correct 59 ms 49204 KB n=23514
36 Correct 46 ms 47352 KB n=940
37 Correct 44 ms 47324 KB n=2
38 Correct 149 ms 61392 KB n=100000
39 Correct 150 ms 61344 KB n=100000
40 Correct 43 ms 47272 KB n=10
41 Correct 47 ms 47480 KB n=100
42 Correct 51 ms 48120 KB n=1000
43 Correct 684 ms 130624 KB n=1000000
44 Correct 759 ms 134876 KB n=1000000
45 Correct 633 ms 120372 KB n=666666
46 Correct 531 ms 108588 KB n=400000
47 Correct 286 ms 75384 KB n=2336
48 Correct 452 ms 95592 KB n=285714
49 Correct 403 ms 93960 KB n=181818
50 Correct 320 ms 81200 KB n=40000
51 Correct 308 ms 79464 KB n=20000
52 Correct 293 ms 77816 KB n=10000
53 Correct 296 ms 84088 KB n=6666
54 Correct 292 ms 73076 KB n=4000
55 Correct 293 ms 79868 KB n=2857
56 Correct 276 ms 71800 KB n=2000