# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
338251 | 2020-12-22T20:05:01 Z | Kerim | Gift (IZhO18_nicegift) | C++17 | 707 ms | 96964 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); 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 | 14 ms | 23788 KB | n=4 |
2 | Correct | 16 ms | 23788 KB | n=3 |
3 | Correct | 14 ms | 23788 KB | n=3 |
4 | Correct | 14 ms | 23788 KB | n=4 |
5 | Correct | 17 ms | 23788 KB | n=4 |
6 | Correct | 14 ms | 23788 KB | n=2 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 23788 KB | n=4 |
2 | Correct | 16 ms | 23788 KB | n=3 |
3 | Correct | 14 ms | 23788 KB | n=3 |
4 | Correct | 14 ms | 23788 KB | n=4 |
5 | Correct | 17 ms | 23788 KB | n=4 |
6 | Correct | 14 ms | 23788 KB | n=2 |
7 | Correct | 14 ms | 23792 KB | n=5 |
8 | Correct | 14 ms | 23788 KB | n=8 |
9 | Correct | 15 ms | 23788 KB | n=14 |
10 | Correct | 14 ms | 23788 KB | n=11 |
11 | Correct | 39 ms | 27104 KB | n=50000 |
12 | Correct | 37 ms | 26724 KB | n=50000 |
13 | Correct | 14 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 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 23788 KB | n=4 |
2 | Correct | 16 ms | 23788 KB | n=3 |
3 | Correct | 14 ms | 23788 KB | n=3 |
4 | Correct | 14 ms | 23788 KB | n=4 |
5 | Correct | 17 ms | 23788 KB | n=4 |
6 | Correct | 14 ms | 23788 KB | n=2 |
7 | Correct | 14 ms | 23792 KB | n=5 |
8 | Correct | 14 ms | 23788 KB | n=8 |
9 | Correct | 15 ms | 23788 KB | n=14 |
10 | Correct | 14 ms | 23788 KB | n=11 |
11 | Correct | 39 ms | 27104 KB | n=50000 |
12 | Correct | 37 ms | 26724 KB | n=50000 |
13 | Correct | 14 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 | 15 ms | 23916 KB | n=989 |
18 | Correct | 15 ms | 23916 KB | n=563 |
19 | Correct | 16 ms | 24044 KB | n=592 |
20 | Correct | 17 ms | 24044 KB | n=938 |
21 | Correct | 17 ms | 23916 KB | n=747 |
22 | Correct | 16 ms | 24044 KB | n=991 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 458 ms | 75064 KB | n=1000000 |
2 | Correct | 285 ms | 55492 KB | n=666666 |
3 | Correct | 176 ms | 40736 KB | n=400000 |
4 | Correct | 402 ms | 62156 KB | n=285714 |
5 | Correct | 22 ms | 24684 KB | n=20000 |
6 | Correct | 360 ms | 54856 KB | n=181818 |
7 | Correct | 18 ms | 24300 KB | n=10000 |
8 | Correct | 56 ms | 27100 KB | n=6666 |
9 | Correct | 16 ms | 23916 KB | n=4000 |
10 | Correct | 248 ms | 41164 KB | n=2857 |
11 | Correct | 15 ms | 23916 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 23788 KB | n=4 |
2 | Correct | 16 ms | 23788 KB | n=3 |
3 | Correct | 14 ms | 23788 KB | n=3 |
4 | Correct | 14 ms | 23788 KB | n=4 |
5 | Correct | 17 ms | 23788 KB | n=4 |
6 | Correct | 14 ms | 23788 KB | n=2 |
7 | Correct | 14 ms | 23792 KB | n=5 |
8 | Correct | 14 ms | 23788 KB | n=8 |
9 | Correct | 15 ms | 23788 KB | n=14 |
10 | Correct | 14 ms | 23788 KB | n=11 |
11 | Correct | 39 ms | 27104 KB | n=50000 |
12 | Correct | 37 ms | 26724 KB | n=50000 |
13 | Correct | 14 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 | 15 ms | 23916 KB | n=989 |
18 | Correct | 15 ms | 23916 KB | n=563 |
19 | Correct | 16 ms | 24044 KB | n=592 |
20 | Correct | 17 ms | 24044 KB | n=938 |
21 | Correct | 17 ms | 23916 KB | n=747 |
22 | Correct | 16 ms | 24044 KB | n=991 |
23 | Correct | 458 ms | 75064 KB | n=1000000 |
24 | Correct | 285 ms | 55492 KB | n=666666 |
25 | Correct | 176 ms | 40736 KB | n=400000 |
26 | Correct | 402 ms | 62156 KB | n=285714 |
27 | Correct | 22 ms | 24684 KB | n=20000 |
28 | Correct | 360 ms | 54856 KB | n=181818 |
29 | Correct | 18 ms | 24300 KB | n=10000 |
30 | Correct | 56 ms | 27100 KB | n=6666 |
31 | Correct | 16 ms | 23916 KB | n=4000 |
32 | Correct | 248 ms | 41164 KB | n=2857 |
33 | Correct | 15 ms | 23916 KB | n=2000 |
34 | Correct | 28 ms | 25364 KB | n=23514 |
35 | Correct | 28 ms | 25364 KB | n=23514 |
36 | Correct | 15 ms | 23916 KB | n=940 |
37 | Correct | 14 ms | 23788 KB | n=2 |
38 | Correct | 107 ms | 33244 KB | n=100000 |
39 | Correct | 111 ms | 33244 KB | n=100000 |
40 | Correct | 15 ms | 23916 KB | n=10 |
41 | Correct | 17 ms | 23916 KB | n=100 |
42 | Correct | 22 ms | 24424 KB | n=1000 |
43 | Correct | 607 ms | 96964 KB | n=1000000 |
44 | Correct | 707 ms | 94736 KB | n=1000000 |
45 | Correct | 561 ms | 74284 KB | n=666666 |
46 | Correct | 459 ms | 66156 KB | n=400000 |
47 | Correct | 252 ms | 40908 KB | n=2336 |
48 | Correct | 442 ms | 62084 KB | n=285714 |
49 | Correct | 371 ms | 54856 KB | n=181818 |
50 | Correct | 273 ms | 45404 KB | n=40000 |
51 | Correct | 262 ms | 43720 KB | n=20000 |
52 | Correct | 252 ms | 41988 KB | n=10000 |
53 | Correct | 248 ms | 41692 KB | n=6666 |
54 | Correct | 246 ms | 41560 KB | n=4000 |
55 | Correct | 245 ms | 41164 KB | n=2857 |
56 | Correct | 245 ms | 40400 KB | n=2000 |