# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
338250 | 2020-12-22T20:04:14 Z | Kerim | Gift (IZhO18_nicegift) | C++17 | 712 ms | 108032 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++) 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 | 17 ms | 23788 KB | n=4 |
2 | Correct | 16 ms | 23788 KB | n=3 |
3 | Correct | 16 ms | 23788 KB | n=3 |
4 | Correct | 16 ms | 23788 KB | n=4 |
5 | Correct | 16 ms | 23788 KB | n=4 |
6 | Correct | 16 ms | 23788 KB | n=2 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23788 KB | n=4 |
2 | Correct | 16 ms | 23788 KB | n=3 |
3 | Correct | 16 ms | 23788 KB | n=3 |
4 | Correct | 16 ms | 23788 KB | n=4 |
5 | Correct | 16 ms | 23788 KB | n=4 |
6 | Correct | 16 ms | 23788 KB | n=2 |
7 | Correct | 15 ms | 23788 KB | n=5 |
8 | Correct | 16 ms | 23788 KB | n=8 |
9 | Correct | 19 ms | 23788 KB | n=14 |
10 | Correct | 16 ms | 23788 KB | n=11 |
11 | Correct | 41 ms | 27104 KB | n=50000 |
12 | Correct | 43 ms | 26852 KB | n=50000 |
13 | Correct | 16 ms | 23788 KB | n=10 |
14 | Correct | 16 ms | 23916 KB | n=685 |
15 | Correct | 16 ms | 23916 KB | n=623 |
16 | Correct | 16 ms | 23916 KB | n=973 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23788 KB | n=4 |
2 | Correct | 16 ms | 23788 KB | n=3 |
3 | Correct | 16 ms | 23788 KB | n=3 |
4 | Correct | 16 ms | 23788 KB | n=4 |
5 | Correct | 16 ms | 23788 KB | n=4 |
6 | Correct | 16 ms | 23788 KB | n=2 |
7 | Correct | 15 ms | 23788 KB | n=5 |
8 | Correct | 16 ms | 23788 KB | n=8 |
9 | Correct | 19 ms | 23788 KB | n=14 |
10 | Correct | 16 ms | 23788 KB | n=11 |
11 | Correct | 41 ms | 27104 KB | n=50000 |
12 | Correct | 43 ms | 26852 KB | n=50000 |
13 | Correct | 16 ms | 23788 KB | n=10 |
14 | Correct | 16 ms | 23916 KB | n=685 |
15 | Correct | 16 ms | 23916 KB | n=623 |
16 | Correct | 16 ms | 23916 KB | n=973 |
17 | Correct | 16 ms | 23916 KB | n=989 |
18 | Correct | 16 ms | 23916 KB | n=563 |
19 | Correct | 18 ms | 24044 KB | n=592 |
20 | Correct | 18 ms | 24044 KB | n=938 |
21 | Correct | 17 ms | 23916 KB | n=747 |
22 | Correct | 18 ms | 24044 KB | n=991 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 470 ms | 75192 KB | n=1000000 |
2 | Correct | 294 ms | 55492 KB | n=666666 |
3 | Correct | 172 ms | 40780 KB | n=400000 |
4 | Correct | 410 ms | 62156 KB | n=285714 |
5 | Correct | 22 ms | 24940 KB | n=20000 |
6 | Correct | 375 ms | 57288 KB | n=181818 |
7 | Correct | 19 ms | 24428 KB | n=10000 |
8 | Correct | 60 ms | 27356 KB | n=6666 |
9 | Correct | 17 ms | 24044 KB | n=4000 |
10 | Correct | 263 ms | 41292 KB | n=2857 |
11 | Correct | 16 ms | 23916 KB | n=2000 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23788 KB | n=4 |
2 | Correct | 16 ms | 23788 KB | n=3 |
3 | Correct | 16 ms | 23788 KB | n=3 |
4 | Correct | 16 ms | 23788 KB | n=4 |
5 | Correct | 16 ms | 23788 KB | n=4 |
6 | Correct | 16 ms | 23788 KB | n=2 |
7 | Correct | 15 ms | 23788 KB | n=5 |
8 | Correct | 16 ms | 23788 KB | n=8 |
9 | Correct | 19 ms | 23788 KB | n=14 |
10 | Correct | 16 ms | 23788 KB | n=11 |
11 | Correct | 41 ms | 27104 KB | n=50000 |
12 | Correct | 43 ms | 26852 KB | n=50000 |
13 | Correct | 16 ms | 23788 KB | n=10 |
14 | Correct | 16 ms | 23916 KB | n=685 |
15 | Correct | 16 ms | 23916 KB | n=623 |
16 | Correct | 16 ms | 23916 KB | n=973 |
17 | Correct | 16 ms | 23916 KB | n=989 |
18 | Correct | 16 ms | 23916 KB | n=563 |
19 | Correct | 18 ms | 24044 KB | n=592 |
20 | Correct | 18 ms | 24044 KB | n=938 |
21 | Correct | 17 ms | 23916 KB | n=747 |
22 | Correct | 18 ms | 24044 KB | n=991 |
23 | Correct | 470 ms | 75192 KB | n=1000000 |
24 | Correct | 294 ms | 55492 KB | n=666666 |
25 | Correct | 172 ms | 40780 KB | n=400000 |
26 | Correct | 410 ms | 62156 KB | n=285714 |
27 | Correct | 22 ms | 24940 KB | n=20000 |
28 | Correct | 375 ms | 57288 KB | n=181818 |
29 | Correct | 19 ms | 24428 KB | n=10000 |
30 | Correct | 60 ms | 27356 KB | n=6666 |
31 | Correct | 17 ms | 24044 KB | n=4000 |
32 | Correct | 263 ms | 41292 KB | n=2857 |
33 | Correct | 16 ms | 23916 KB | n=2000 |
34 | Correct | 37 ms | 25492 KB | n=23514 |
35 | Correct | 31 ms | 25492 KB | n=23514 |
36 | Correct | 17 ms | 23916 KB | n=940 |
37 | Correct | 15 ms | 23788 KB | n=2 |
38 | Correct | 110 ms | 33628 KB | n=100000 |
39 | Correct | 111 ms | 33632 KB | n=100000 |
40 | Correct | 15 ms | 23788 KB | n=10 |
41 | Correct | 16 ms | 23916 KB | n=100 |
42 | Correct | 21 ms | 24424 KB | n=1000 |
43 | Correct | 631 ms | 103732 KB | n=1000000 |
44 | Correct | 712 ms | 108032 KB | n=1000000 |
45 | Correct | 603 ms | 83264 KB | n=666666 |
46 | Correct | 457 ms | 71668 KB | n=400000 |
47 | Correct | 263 ms | 41036 KB | n=2336 |
48 | Correct | 402 ms | 65996 KB | n=285714 |
49 | Correct | 378 ms | 57416 KB | n=181818 |
50 | Correct | 288 ms | 46176 KB | n=40000 |
51 | Correct | 271 ms | 43976 KB | n=20000 |
52 | Correct | 265 ms | 42212 KB | n=10000 |
53 | Correct | 266 ms | 41800 KB | n=6666 |
54 | Correct | 261 ms | 41416 KB | n=4000 |
55 | Correct | 258 ms | 41420 KB | n=2857 |
56 | Correct | 251 ms | 40400 KB | n=2000 |