# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
334512 | 2020-12-09T09:48:51 Z | juggernaut | Gift (IZhO18_nicegift) | C++14 | 803 ms | 141240 KB |
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll n,k,sum,mx,i,a[1000001],mn,sz,res,cnt[1000001],j,tmp; vector<pair<ll,ll>>vec[1000001]; vector<ll>ans[1000001]; bool flag; int 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)return puts("-1"),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}); } for(int i=0;i<sz;i++)reverse(vec[i].begin(),vec[i].end()); while(!flag){ mn=9e18; 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 47468 KB | n=4 |
2 | Correct | 33 ms | 47468 KB | n=3 |
3 | Correct | 34 ms | 47352 KB | n=3 |
4 | Correct | 32 ms | 47340 KB | n=4 |
5 | Correct | 32 ms | 47340 KB | n=4 |
6 | Correct | 33 ms | 47340 KB | n=2 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 47468 KB | n=4 |
2 | Correct | 33 ms | 47468 KB | n=3 |
3 | Correct | 34 ms | 47352 KB | n=3 |
4 | Correct | 32 ms | 47340 KB | n=4 |
5 | Correct | 32 ms | 47340 KB | n=4 |
6 | Correct | 33 ms | 47340 KB | n=2 |
7 | Correct | 32 ms | 47340 KB | n=5 |
8 | Correct | 31 ms | 47340 KB | n=8 |
9 | Correct | 30 ms | 47340 KB | n=14 |
10 | Correct | 31 ms | 47256 KB | n=11 |
11 | Correct | 79 ms | 50912 KB | n=50000 |
12 | Correct | 64 ms | 50660 KB | n=50000 |
13 | Correct | 33 ms | 47340 KB | n=10 |
14 | Correct | 32 ms | 47340 KB | n=685 |
15 | Correct | 33 ms | 47340 KB | n=623 |
16 | Correct | 32 ms | 47340 KB | n=973 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 47468 KB | n=4 |
2 | Correct | 33 ms | 47468 KB | n=3 |
3 | Correct | 34 ms | 47352 KB | n=3 |
4 | Correct | 32 ms | 47340 KB | n=4 |
5 | Correct | 32 ms | 47340 KB | n=4 |
6 | Correct | 33 ms | 47340 KB | n=2 |
7 | Correct | 32 ms | 47340 KB | n=5 |
8 | Correct | 31 ms | 47340 KB | n=8 |
9 | Correct | 30 ms | 47340 KB | n=14 |
10 | Correct | 31 ms | 47256 KB | n=11 |
11 | Correct | 79 ms | 50912 KB | n=50000 |
12 | Correct | 64 ms | 50660 KB | n=50000 |
13 | Correct | 33 ms | 47340 KB | n=10 |
14 | Correct | 32 ms | 47340 KB | n=685 |
15 | Correct | 33 ms | 47340 KB | n=623 |
16 | Correct | 32 ms | 47340 KB | n=973 |
17 | Correct | 39 ms | 47340 KB | n=989 |
18 | Correct | 30 ms | 47340 KB | n=563 |
19 | Correct | 33 ms | 47468 KB | n=592 |
20 | Correct | 35 ms | 47468 KB | n=938 |
21 | Correct | 34 ms | 47468 KB | n=747 |
22 | Correct | 36 ms | 47468 KB | n=991 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 556 ms | 107576 KB | n=1000000 |
2 | Correct | 335 ms | 87364 KB | n=666666 |
3 | Correct | 203 ms | 72524 KB | n=400000 |
4 | Correct | 475 ms | 99040 KB | n=285714 |
5 | Correct | 40 ms | 48492 KB | n=20000 |
6 | Correct | 431 ms | 96380 KB | n=181818 |
7 | Correct | 36 ms | 47852 KB | n=10000 |
8 | Correct | 80 ms | 53848 KB | n=6666 |
9 | Correct | 41 ms | 47468 KB | n=4000 |
10 | Correct | 304 ms | 79724 KB | n=2857 |
11 | Correct | 34 ms | 47468 KB | n=2000 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 47468 KB | n=4 |
2 | Correct | 33 ms | 47468 KB | n=3 |
3 | Correct | 34 ms | 47352 KB | n=3 |
4 | Correct | 32 ms | 47340 KB | n=4 |
5 | Correct | 32 ms | 47340 KB | n=4 |
6 | Correct | 33 ms | 47340 KB | n=2 |
7 | Correct | 32 ms | 47340 KB | n=5 |
8 | Correct | 31 ms | 47340 KB | n=8 |
9 | Correct | 30 ms | 47340 KB | n=14 |
10 | Correct | 31 ms | 47256 KB | n=11 |
11 | Correct | 79 ms | 50912 KB | n=50000 |
12 | Correct | 64 ms | 50660 KB | n=50000 |
13 | Correct | 33 ms | 47340 KB | n=10 |
14 | Correct | 32 ms | 47340 KB | n=685 |
15 | Correct | 33 ms | 47340 KB | n=623 |
16 | Correct | 32 ms | 47340 KB | n=973 |
17 | Correct | 39 ms | 47340 KB | n=989 |
18 | Correct | 30 ms | 47340 KB | n=563 |
19 | Correct | 33 ms | 47468 KB | n=592 |
20 | Correct | 35 ms | 47468 KB | n=938 |
21 | Correct | 34 ms | 47468 KB | n=747 |
22 | Correct | 36 ms | 47468 KB | n=991 |
23 | Correct | 556 ms | 107576 KB | n=1000000 |
24 | Correct | 335 ms | 87364 KB | n=666666 |
25 | Correct | 203 ms | 72524 KB | n=400000 |
26 | Correct | 475 ms | 99040 KB | n=285714 |
27 | Correct | 40 ms | 48492 KB | n=20000 |
28 | Correct | 431 ms | 96380 KB | n=181818 |
29 | Correct | 36 ms | 47852 KB | n=10000 |
30 | Correct | 80 ms | 53848 KB | n=6666 |
31 | Correct | 41 ms | 47468 KB | n=4000 |
32 | Correct | 304 ms | 79724 KB | n=2857 |
33 | Correct | 34 ms | 47468 KB | n=2000 |
34 | Correct | 47 ms | 49256 KB | n=23514 |
35 | Correct | 48 ms | 49352 KB | n=23514 |
36 | Correct | 32 ms | 47340 KB | n=940 |
37 | Correct | 33 ms | 47340 KB | n=2 |
38 | Correct | 144 ms | 61924 KB | n=100000 |
39 | Correct | 144 ms | 61796 KB | n=100000 |
40 | Correct | 32 ms | 47340 KB | n=10 |
41 | Correct | 33 ms | 47340 KB | n=100 |
42 | Correct | 39 ms | 48108 KB | n=1000 |
43 | Correct | 713 ms | 137148 KB | n=1000000 |
44 | Correct | 803 ms | 141240 KB | n=1000000 |
45 | Correct | 644 ms | 126404 KB | n=666666 |
46 | Correct | 525 ms | 113996 KB | n=400000 |
47 | Correct | 295 ms | 75500 KB | n=2336 |
48 | Correct | 465 ms | 99552 KB | n=285714 |
49 | Correct | 421 ms | 96356 KB | n=181818 |
50 | Correct | 333 ms | 81792 KB | n=40000 |
51 | Correct | 317 ms | 79804 KB | n=20000 |
52 | Correct | 304 ms | 77916 KB | n=10000 |
53 | Correct | 304 ms | 84332 KB | n=6666 |
54 | Correct | 302 ms | 73196 KB | n=4000 |
55 | Correct | 308 ms | 79724 KB | n=2857 |
56 | Correct | 286 ms | 71916 KB | n=2000 |