# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
338247 | 2020-12-22T20:03:09 Z | Kerim | Gift (IZhO18_nicegift) | C++17 | 479 ms | 87260 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-sum/k,i)); } else adj[tmp].pb(mp(arr[i],i)); }assert(tmp==k); for(int i=0;i<k;i++) reverse(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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | n=4 |
2 | Correct | 16 ms | 23788 KB | n=3 |
3 | Correct | 16 ms | 23788 KB | n=3 |
4 | Incorrect | 16 ms | 23788 KB | Added number should be positive |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | n=4 |
2 | Correct | 16 ms | 23788 KB | n=3 |
3 | Correct | 16 ms | 23788 KB | n=3 |
4 | Incorrect | 16 ms | 23788 KB | Added number should be positive |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | n=4 |
2 | Correct | 16 ms | 23788 KB | n=3 |
3 | Correct | 16 ms | 23788 KB | n=3 |
4 | Incorrect | 16 ms | 23788 KB | Added number should be positive |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 479 ms | 75192 KB | n=1000000 |
2 | Correct | 313 ms | 64836 KB | n=666666 |
3 | Correct | 176 ms | 46284 KB | n=400000 |
4 | Runtime error | 149 ms | 87260 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | n=4 |
2 | Correct | 16 ms | 23788 KB | n=3 |
3 | Correct | 16 ms | 23788 KB | n=3 |
4 | Incorrect | 16 ms | 23788 KB | Added number should be positive |
5 | Halted | 0 ms | 0 KB | - |