# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
175639 | 2020-01-07T08:46:57 Z | juggernaut | Gift (IZhO18_nicegift) | C++14 | 536 ms | 104396 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}); } for(i=0;i<sz;i++)sort(vec[i].begin(),vec[i].end()); 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 47352 KB | n=4 |
2 | Correct | 47 ms | 47224 KB | n=3 |
3 | Correct | 47 ms | 47224 KB | n=3 |
4 | Correct | 47 ms | 47352 KB | n=4 |
5 | Correct | 46 ms | 47352 KB | n=4 |
6 | Correct | 46 ms | 47224 KB | n=2 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 47352 KB | n=4 |
2 | Correct | 47 ms | 47224 KB | n=3 |
3 | Correct | 47 ms | 47224 KB | n=3 |
4 | Correct | 47 ms | 47352 KB | n=4 |
5 | Correct | 46 ms | 47352 KB | n=4 |
6 | Correct | 46 ms | 47224 KB | n=2 |
7 | Correct | 46 ms | 47352 KB | n=5 |
8 | Correct | 46 ms | 47240 KB | n=8 |
9 | Correct | 55 ms | 47224 KB | n=14 |
10 | Incorrect | 47 ms | 47352 KB | Same heap occurs twice |
11 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 47352 KB | n=4 |
2 | Correct | 47 ms | 47224 KB | n=3 |
3 | Correct | 47 ms | 47224 KB | n=3 |
4 | Correct | 47 ms | 47352 KB | n=4 |
5 | Correct | 46 ms | 47352 KB | n=4 |
6 | Correct | 46 ms | 47224 KB | n=2 |
7 | Correct | 46 ms | 47352 KB | n=5 |
8 | Correct | 46 ms | 47240 KB | n=8 |
9 | Correct | 55 ms | 47224 KB | n=14 |
10 | Incorrect | 47 ms | 47352 KB | Same heap occurs twice |
11 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 536 ms | 104396 KB | n=1000000 |
2 | Correct | 358 ms | 83020 KB | n=666666 |
3 | Correct | 222 ms | 67412 KB | n=400000 |
4 | Incorrect | 195 ms | 60068 KB | Same heap occurs twice |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 47352 KB | n=4 |
2 | Correct | 47 ms | 47224 KB | n=3 |
3 | Correct | 47 ms | 47224 KB | n=3 |
4 | Correct | 47 ms | 47352 KB | n=4 |
5 | Correct | 46 ms | 47352 KB | n=4 |
6 | Correct | 46 ms | 47224 KB | n=2 |
7 | Correct | 46 ms | 47352 KB | n=5 |
8 | Correct | 46 ms | 47240 KB | n=8 |
9 | Correct | 55 ms | 47224 KB | n=14 |
10 | Incorrect | 47 ms | 47352 KB | Same heap occurs twice |
11 | Halted | 0 ms | 0 KB | - |