# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
338252 | 2020-12-22T20:05:19 Z | Kerim | Gift (IZhO18_nicegift) | C++17 | 522 ms | 75176 KB |
#include "bits/stdc++.h" #define MAXN 1000009 #define INF 1000000007 #define mp(x,y) make_pair(x,y) #define all(v) v.begin(),v.end() #define pb(x) push_back(x) #define wr cout<<"----------------"<<endl; #define ppb() pop_back() #define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++) #define ff first #define ss second #define my_little_dodge 46 #define debug(x) cerr<< #x <<" = "<< x<<endl; using namespace std; typedef long long ll; typedef pair<int,int> PII; template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} ll arr[MAXN]; vector<pair<ll,int> >adj[MAXN]; const ll B=2e18; int main(){ // freopen("file.in", "r", stdin); int n,k,tmp=0; scanf("%d%d",&n,&k); ll sum=0,mx=0,cur=0; for(int i=1;i<=n;i++) scanf("%lld",arr+i),sum+=arr[i],umax(mx,arr[i]); if(sum%k!=0 or mx>sum/k) return printf("-1\n")*0; for(int i=1;i<=n;i++){ cur+=arr[i]; if(cur>=sum/k){ adj[tmp++].pb(mp(sum/k-cur+arr[i],i)); cur-=sum/k; if(cur) adj[tmp].pb(mp(cur,i)); } else adj[tmp].pb(mp(arr[i],i)); }assert(tmp==k); for(int i=0;i<k;i++) sort(all(adj[i])); vector<ll>val; vector<int>res; while(!adj[0].empty()){ ll mn=B; for(int i=0;i<k;i++) umin(mn,adj[i].back().ff); val.pb(mn); for(int i=0;i<k;i++){ res.pb(adj[i].back().ss); if(adj[i].back().ff==mn) adj[i].ppb(); else adj[i].back().ff-=mn; } } printf("%d\n",int(val.size()));tmp=0; for(int i=0;i<int(val.size());i++){ printf("%lld ",val[i]); for(int j=0;j<k;j++) printf("%d ",res[tmp++]); puts(""); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | n=4 |
2 | Correct | 14 ms | 23788 KB | n=3 |
3 | Correct | 14 ms | 23788 KB | n=3 |
4 | Correct | 14 ms | 23788 KB | n=4 |
5 | Correct | 15 ms | 23788 KB | n=4 |
6 | Correct | 14 ms | 23788 KB | n=2 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | n=4 |
2 | Correct | 14 ms | 23788 KB | n=3 |
3 | Correct | 14 ms | 23788 KB | n=3 |
4 | Correct | 14 ms | 23788 KB | n=4 |
5 | Correct | 15 ms | 23788 KB | n=4 |
6 | Correct | 14 ms | 23788 KB | n=2 |
7 | Correct | 14 ms | 23788 KB | n=5 |
8 | Correct | 15 ms | 23788 KB | n=8 |
9 | Correct | 15 ms | 23788 KB | n=14 |
10 | Incorrect | 14 ms | 23788 KB | Same heap occurs twice |
11 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | n=4 |
2 | Correct | 14 ms | 23788 KB | n=3 |
3 | Correct | 14 ms | 23788 KB | n=3 |
4 | Correct | 14 ms | 23788 KB | n=4 |
5 | Correct | 15 ms | 23788 KB | n=4 |
6 | Correct | 14 ms | 23788 KB | n=2 |
7 | Correct | 14 ms | 23788 KB | n=5 |
8 | Correct | 15 ms | 23788 KB | n=8 |
9 | Correct | 15 ms | 23788 KB | n=14 |
10 | Incorrect | 14 ms | 23788 KB | Same heap occurs twice |
11 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 522 ms | 75176 KB | n=1000000 |
2 | Correct | 319 ms | 55492 KB | n=666666 |
3 | Correct | 176 ms | 40760 KB | n=400000 |
4 | Incorrect | 150 ms | 35164 KB | Same heap occurs twice |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | n=4 |
2 | Correct | 14 ms | 23788 KB | n=3 |
3 | Correct | 14 ms | 23788 KB | n=3 |
4 | Correct | 14 ms | 23788 KB | n=4 |
5 | Correct | 15 ms | 23788 KB | n=4 |
6 | Correct | 14 ms | 23788 KB | n=2 |
7 | Correct | 14 ms | 23788 KB | n=5 |
8 | Correct | 15 ms | 23788 KB | n=8 |
9 | Correct | 15 ms | 23788 KB | n=14 |
10 | Incorrect | 14 ms | 23788 KB | Same heap occurs twice |
11 | Halted | 0 ms | 0 KB | - |