# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
168942 | 2019-12-17T09:06:12 Z | abil | Gift (IZhO18_nicegift) | C++14 | 810 ms | 149160 KB |
#include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define mk make_pair #define all(s) s.begin(),s.end() #define int long long using namespace std; const int N = (1e6 + 12); const int mod = (1e9 + 7); const int INF = (1e18 + 12); int a[N], b[N]; vector<pair<int,int > > vec[N]; vector<int > ans[N]; int res[N]; main() { int n, k, sum = 0, mx = 0; scanf("%lld%lld", &n, &k); for(int i = 1;i <= n; i++){ scanf("%lld", &a[i]); sum += a[i]; mx = max(mx, a[i]); } if(sum % k != 0 || mx > sum / k){ cout << -1; return 0; } int cur_sum = 0; int sz = 0; for(int i = 1;i <= n; i++){ cur_sum += a[i]; if(cur_sum >= sum / k){ int rem = cur_sum - sum / k; cur_sum = rem; vec[sz].pb({a[i] - rem, i}); sz++; if(rem > 0){ vec[sz].pb({rem, i}); } } else{ vec[sz].pb({a[i], i}); } } int szofans = 1; while(1){ int mn = INF; for(int i = 0;i < sz; i++){ mn = min(mn, vec[i][b[i]].fr); } res[szofans] = mn; bool f = false; for(int i = 0;i < sz; i++){ vec[i][b[i]].fr -= mn; ans[szofans].pb(vec[i][b[i]].sc); if(vec[i][b[i]].fr == 0){ b[i]++; if(b[i] == vec[i].size()){ f = true; } } } if(f){ break; } szofans++; } cout << szofans << endl; for(int i = 1;i <= szofans; i++){ printf("%lld ", res[i]); for(auto to : ans[i]){ printf("%lld ", to); } printf("\n"); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 47352 KB | n=4 |
2 | Correct | 45 ms | 47224 KB | n=3 |
3 | Correct | 44 ms | 47224 KB | n=3 |
4 | Correct | 45 ms | 47340 KB | n=4 |
5 | Correct | 45 ms | 47224 KB | n=4 |
6 | Correct | 55 ms | 47352 KB | n=2 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 47352 KB | n=4 |
2 | Correct | 45 ms | 47224 KB | n=3 |
3 | Correct | 44 ms | 47224 KB | n=3 |
4 | Correct | 45 ms | 47340 KB | n=4 |
5 | Correct | 45 ms | 47224 KB | n=4 |
6 | Correct | 55 ms | 47352 KB | n=2 |
7 | Correct | 52 ms | 47324 KB | n=5 |
8 | Correct | 45 ms | 47352 KB | n=8 |
9 | Correct | 45 ms | 47336 KB | n=14 |
10 | Correct | 45 ms | 47316 KB | n=11 |
11 | Correct | 71 ms | 50796 KB | n=50000 |
12 | Correct | 71 ms | 50672 KB | n=50000 |
13 | Correct | 45 ms | 47352 KB | n=10 |
14 | Correct | 46 ms | 47480 KB | n=685 |
15 | Correct | 45 ms | 47480 KB | n=623 |
16 | Correct | 45 ms | 47352 KB | n=973 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 47352 KB | n=4 |
2 | Correct | 45 ms | 47224 KB | n=3 |
3 | Correct | 44 ms | 47224 KB | n=3 |
4 | Correct | 45 ms | 47340 KB | n=4 |
5 | Correct | 45 ms | 47224 KB | n=4 |
6 | Correct | 55 ms | 47352 KB | n=2 |
7 | Correct | 52 ms | 47324 KB | n=5 |
8 | Correct | 45 ms | 47352 KB | n=8 |
9 | Correct | 45 ms | 47336 KB | n=14 |
10 | Correct | 45 ms | 47316 KB | n=11 |
11 | Correct | 71 ms | 50796 KB | n=50000 |
12 | Correct | 71 ms | 50672 KB | n=50000 |
13 | Correct | 45 ms | 47352 KB | n=10 |
14 | Correct | 46 ms | 47480 KB | n=685 |
15 | Correct | 45 ms | 47480 KB | n=623 |
16 | Correct | 45 ms | 47352 KB | n=973 |
17 | Correct | 45 ms | 47352 KB | n=989 |
18 | Correct | 45 ms | 47428 KB | n=563 |
19 | Correct | 46 ms | 47480 KB | n=592 |
20 | Correct | 55 ms | 47480 KB | n=938 |
21 | Correct | 46 ms | 47484 KB | n=747 |
22 | Correct | 48 ms | 47552 KB | n=991 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 496 ms | 104860 KB | n=1000000 |
2 | Correct | 328 ms | 83148 KB | n=666666 |
3 | Correct | 203 ms | 67540 KB | n=400000 |
4 | Correct | 448 ms | 96092 KB | n=285714 |
5 | Correct | 52 ms | 48220 KB | n=20000 |
6 | Correct | 394 ms | 94192 KB | n=181818 |
7 | Correct | 49 ms | 47736 KB | n=10000 |
8 | Correct | 87 ms | 53624 KB | n=6666 |
9 | Correct | 47 ms | 47480 KB | n=4000 |
10 | Correct | 273 ms | 79864 KB | n=2857 |
11 | Correct | 46 ms | 47352 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 47352 KB | n=4 |
2 | Correct | 45 ms | 47224 KB | n=3 |
3 | Correct | 44 ms | 47224 KB | n=3 |
4 | Correct | 45 ms | 47340 KB | n=4 |
5 | Correct | 45 ms | 47224 KB | n=4 |
6 | Correct | 55 ms | 47352 KB | n=2 |
7 | Correct | 52 ms | 47324 KB | n=5 |
8 | Correct | 45 ms | 47352 KB | n=8 |
9 | Correct | 45 ms | 47336 KB | n=14 |
10 | Correct | 45 ms | 47316 KB | n=11 |
11 | Correct | 71 ms | 50796 KB | n=50000 |
12 | Correct | 71 ms | 50672 KB | n=50000 |
13 | Correct | 45 ms | 47352 KB | n=10 |
14 | Correct | 46 ms | 47480 KB | n=685 |
15 | Correct | 45 ms | 47480 KB | n=623 |
16 | Correct | 45 ms | 47352 KB | n=973 |
17 | Correct | 45 ms | 47352 KB | n=989 |
18 | Correct | 45 ms | 47428 KB | n=563 |
19 | Correct | 46 ms | 47480 KB | n=592 |
20 | Correct | 55 ms | 47480 KB | n=938 |
21 | Correct | 46 ms | 47484 KB | n=747 |
22 | Correct | 48 ms | 47552 KB | n=991 |
23 | Correct | 496 ms | 104860 KB | n=1000000 |
24 | Correct | 328 ms | 83148 KB | n=666666 |
25 | Correct | 203 ms | 67540 KB | n=400000 |
26 | Correct | 448 ms | 96092 KB | n=285714 |
27 | Correct | 52 ms | 48220 KB | n=20000 |
28 | Correct | 394 ms | 94192 KB | n=181818 |
29 | Correct | 49 ms | 47736 KB | n=10000 |
30 | Correct | 87 ms | 53624 KB | n=6666 |
31 | Correct | 47 ms | 47480 KB | n=4000 |
32 | Correct | 273 ms | 79864 KB | n=2857 |
33 | Correct | 46 ms | 47352 KB | n=2000 |
34 | Correct | 71 ms | 49280 KB | n=23514 |
35 | Correct | 61 ms | 49268 KB | n=23514 |
36 | Correct | 46 ms | 47352 KB | n=940 |
37 | Correct | 45 ms | 47352 KB | n=2 |
38 | Correct | 152 ms | 61420 KB | n=100000 |
39 | Correct | 152 ms | 61552 KB | n=100000 |
40 | Correct | 46 ms | 47352 KB | n=10 |
41 | Correct | 46 ms | 47352 KB | n=100 |
42 | Correct | 52 ms | 47992 KB | n=1000 |
43 | Correct | 696 ms | 131772 KB | n=1000000 |
44 | Correct | 810 ms | 149160 KB | n=1000000 |
45 | Correct | 664 ms | 130300 KB | n=666666 |
46 | Correct | 538 ms | 114516 KB | n=400000 |
47 | Correct | 264 ms | 75376 KB | n=2336 |
48 | Correct | 456 ms | 99944 KB | n=285714 |
49 | Correct | 407 ms | 96748 KB | n=181818 |
50 | Correct | 299 ms | 81784 KB | n=40000 |
51 | Correct | 285 ms | 79724 KB | n=20000 |
52 | Correct | 286 ms | 77816 KB | n=10000 |
53 | Correct | 279 ms | 84264 KB | n=6666 |
54 | Correct | 261 ms | 73080 KB | n=4000 |
55 | Correct | 270 ms | 79736 KB | n=2857 |
56 | Correct | 253 ms | 71928 KB | n=2000 |