# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40571 | 2018-02-05T02:35:05 Z | Just_Solve_The_Problem | Gift (IZhO18_nicegift) | C++11 | 733 ms | 119920 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair < ll, ll > #define fr first #define sc second #define mk make_pair const int N = (int)1e6 + 7; ll sum = 0; ll a[N]; vector < vector < pii > > block; vector < vector < ll > > ans; vector < ll > ans1; int pointer[N]; main() { int n; ll k; scanf("%d %lld", &n, &k); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); sum += a[i]; } if (sum % k != 0) { puts("-1"); return 0; } sum /= k; vector < pii > vec; vector < ll > v; int in = 1; ll res = 0; while (in <= n) { if (res + a[in] > sum) { vec.pb(mk(a[in] - (res + a[in] - sum), in)); a[in] = res + a[in] - sum; res = sum; } else { vec.pb(mk(a[in], in)); res += a[in]; in++; } if (res == sum) { res = 0; pointer[block.size()] = vec.size() - 1; block.pb(vec); vec.clear(); } } sum *= k; while (sum > 0) { ll mn = 1e18; for (int i = 0; i < k; i++) { mn = min(mn, block[i][pointer[i]].fr); } sum -= k * mn; for (int i = 0; i < k; i++) { block[i][pointer[i]].fr -= mn; if (i > 0 && block[i][pointer[i]].sc == v.back()) { puts("-1"); return 0; } v.pb(block[i][pointer[i]].sc); if (block[i][pointer[i]].fr == 0) { pointer[i]--; } } ans.pb(v); v.clear(); ans1.pb(mn); } printf("%d\n", ans.size()); for (int i = 0; i < ans.size(); i++) { printf("%lld ", ans1[i]); for (int j = 0; j < ans[i].size(); j++) { printf("%lld ", ans[i][j]); } printf("\n"); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | n=4 |
2 | Correct | 2 ms | 352 KB | n=3 |
3 | Correct | 2 ms | 552 KB | n=3 |
4 | Correct | 1 ms | 552 KB | n=4 |
5 | Correct | 2 ms | 552 KB | n=4 |
6 | Correct | 1 ms | 552 KB | n=2 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | n=4 |
2 | Correct | 2 ms | 352 KB | n=3 |
3 | Correct | 2 ms | 552 KB | n=3 |
4 | Correct | 1 ms | 552 KB | n=4 |
5 | Correct | 2 ms | 552 KB | n=4 |
6 | Correct | 1 ms | 552 KB | n=2 |
7 | Correct | 2 ms | 692 KB | n=5 |
8 | Correct | 1 ms | 692 KB | n=8 |
9 | Correct | 2 ms | 692 KB | n=14 |
10 | Correct | 2 ms | 692 KB | n=11 |
11 | Correct | 28 ms | 5560 KB | n=50000 |
12 | Correct | 36 ms | 5560 KB | n=50000 |
13 | Correct | 2 ms | 5560 KB | n=10 |
14 | Correct | 3 ms | 5560 KB | n=685 |
15 | Correct | 2 ms | 5560 KB | n=623 |
16 | Correct | 2 ms | 5560 KB | n=973 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | n=4 |
2 | Correct | 2 ms | 352 KB | n=3 |
3 | Correct | 2 ms | 552 KB | n=3 |
4 | Correct | 1 ms | 552 KB | n=4 |
5 | Correct | 2 ms | 552 KB | n=4 |
6 | Correct | 1 ms | 552 KB | n=2 |
7 | Correct | 2 ms | 692 KB | n=5 |
8 | Correct | 1 ms | 692 KB | n=8 |
9 | Correct | 2 ms | 692 KB | n=14 |
10 | Correct | 2 ms | 692 KB | n=11 |
11 | Correct | 28 ms | 5560 KB | n=50000 |
12 | Correct | 36 ms | 5560 KB | n=50000 |
13 | Correct | 2 ms | 5560 KB | n=10 |
14 | Correct | 3 ms | 5560 KB | n=685 |
15 | Correct | 2 ms | 5560 KB | n=623 |
16 | Correct | 2 ms | 5560 KB | n=973 |
17 | Correct | 2 ms | 5560 KB | n=989 |
18 | Correct | 2 ms | 5560 KB | n=563 |
19 | Correct | 3 ms | 5560 KB | n=592 |
20 | Correct | 3 ms | 5560 KB | n=938 |
21 | Correct | 2 ms | 5560 KB | n=747 |
22 | Correct | 3 ms | 5560 KB | n=991 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 489 ms | 77388 KB | n=1000000 |
2 | Correct | 287 ms | 77388 KB | n=666666 |
3 | Correct | 150 ms | 77388 KB | n=400000 |
4 | Correct | 403 ms | 77388 KB | n=285714 |
5 | Correct | 10 ms | 77388 KB | n=20000 |
6 | Correct | 338 ms | 77388 KB | n=181818 |
7 | Correct | 8 ms | 77388 KB | n=10000 |
8 | Correct | 50 ms | 77388 KB | n=6666 |
9 | Correct | 3 ms | 77388 KB | n=4000 |
10 | Correct | 236 ms | 77388 KB | n=2857 |
11 | Correct | 6 ms | 77388 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | n=4 |
2 | Correct | 2 ms | 352 KB | n=3 |
3 | Correct | 2 ms | 552 KB | n=3 |
4 | Correct | 1 ms | 552 KB | n=4 |
5 | Correct | 2 ms | 552 KB | n=4 |
6 | Correct | 1 ms | 552 KB | n=2 |
7 | Correct | 2 ms | 692 KB | n=5 |
8 | Correct | 1 ms | 692 KB | n=8 |
9 | Correct | 2 ms | 692 KB | n=14 |
10 | Correct | 2 ms | 692 KB | n=11 |
11 | Correct | 28 ms | 5560 KB | n=50000 |
12 | Correct | 36 ms | 5560 KB | n=50000 |
13 | Correct | 2 ms | 5560 KB | n=10 |
14 | Correct | 3 ms | 5560 KB | n=685 |
15 | Correct | 2 ms | 5560 KB | n=623 |
16 | Correct | 2 ms | 5560 KB | n=973 |
17 | Correct | 2 ms | 5560 KB | n=989 |
18 | Correct | 2 ms | 5560 KB | n=563 |
19 | Correct | 3 ms | 5560 KB | n=592 |
20 | Correct | 3 ms | 5560 KB | n=938 |
21 | Correct | 2 ms | 5560 KB | n=747 |
22 | Correct | 3 ms | 5560 KB | n=991 |
23 | Correct | 489 ms | 77388 KB | n=1000000 |
24 | Correct | 287 ms | 77388 KB | n=666666 |
25 | Correct | 150 ms | 77388 KB | n=400000 |
26 | Correct | 403 ms | 77388 KB | n=285714 |
27 | Correct | 10 ms | 77388 KB | n=20000 |
28 | Correct | 338 ms | 77388 KB | n=181818 |
29 | Correct | 8 ms | 77388 KB | n=10000 |
30 | Correct | 50 ms | 77388 KB | n=6666 |
31 | Correct | 3 ms | 77388 KB | n=4000 |
32 | Correct | 236 ms | 77388 KB | n=2857 |
33 | Correct | 6 ms | 77388 KB | n=2000 |
34 | Correct | 21 ms | 77388 KB | n=23514 |
35 | Correct | 16 ms | 77388 KB | n=23514 |
36 | Correct | 2 ms | 77388 KB | n=940 |
37 | Correct | 1 ms | 77388 KB | n=2 |
38 | Correct | 97 ms | 77388 KB | n=100000 |
39 | Correct | 97 ms | 77388 KB | n=100000 |
40 | Correct | 2 ms | 77388 KB | n=10 |
41 | Correct | 2 ms | 77388 KB | n=100 |
42 | Correct | 7 ms | 77388 KB | n=1000 |
43 | Correct | 654 ms | 119056 KB | n=1000000 |
44 | Correct | 733 ms | 119920 KB | n=1000000 |
45 | Correct | 597 ms | 119920 KB | n=666666 |
46 | Correct | 453 ms | 119920 KB | n=400000 |
47 | Correct | 220 ms | 119920 KB | n=2336 |
48 | Correct | 398 ms | 119920 KB | n=285714 |
49 | Correct | 337 ms | 119920 KB | n=181818 |
50 | Correct | 246 ms | 119920 KB | n=40000 |
51 | Correct | 239 ms | 119920 KB | n=20000 |
52 | Correct | 206 ms | 119920 KB | n=10000 |
53 | Correct | 234 ms | 119920 KB | n=6666 |
54 | Correct | 227 ms | 119920 KB | n=4000 |
55 | Correct | 205 ms | 119920 KB | n=2857 |
56 | Correct | 207 ms | 119920 KB | n=2000 |