# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40568 | 2018-02-05T02:13:48 Z | Just_Solve_The_Problem | Gift (IZhO18_nicegift) | C++11 | 462 ms | 77216 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, k; scanf("%d %d", &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 = 2e18; for (int i = 0; i < k; i++) { mn = min(mn, block[i][pointer[i]].fr); v.pb(block[i][pointer[i]].sc); } sum -= k * mn; for (int i = 0; i < k; i++) { block[i][pointer[i]].fr -= mn; 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 | 1 ms | 352 KB | n=3 |
3 | Correct | 1 ms | 404 KB | n=3 |
4 | Correct | 1 ms | 404 KB | n=4 |
5 | Correct | 2 ms | 404 KB | n=4 |
6 | Correct | 1 ms | 404 KB | n=2 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | n=4 |
2 | Correct | 1 ms | 352 KB | n=3 |
3 | Correct | 1 ms | 404 KB | n=3 |
4 | Correct | 1 ms | 404 KB | n=4 |
5 | Correct | 2 ms | 404 KB | n=4 |
6 | Correct | 1 ms | 404 KB | n=2 |
7 | Correct | 2 ms | 404 KB | n=5 |
8 | Incorrect | 2 ms | 464 KB | Same heap occurs twice |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | n=4 |
2 | Correct | 1 ms | 352 KB | n=3 |
3 | Correct | 1 ms | 404 KB | n=3 |
4 | Correct | 1 ms | 404 KB | n=4 |
5 | Correct | 2 ms | 404 KB | n=4 |
6 | Correct | 1 ms | 404 KB | n=2 |
7 | Correct | 2 ms | 404 KB | n=5 |
8 | Incorrect | 2 ms | 464 KB | Same heap occurs twice |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 462 ms | 77216 KB | n=1000000 |
2 | Correct | 285 ms | 77216 KB | n=666666 |
3 | Correct | 144 ms | 77216 KB | n=400000 |
4 | Correct | 423 ms | 77216 KB | n=285714 |
5 | Correct | 18 ms | 77216 KB | n=20000 |
6 | Correct | 336 ms | 77216 KB | n=181818 |
7 | Correct | 12 ms | 77216 KB | n=10000 |
8 | Correct | 40 ms | 77216 KB | n=6666 |
9 | Correct | 3 ms | 77216 KB | n=4000 |
10 | Correct | 228 ms | 77216 KB | n=2857 |
11 | Correct | 4 ms | 77216 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | n=4 |
2 | Correct | 1 ms | 352 KB | n=3 |
3 | Correct | 1 ms | 404 KB | n=3 |
4 | Correct | 1 ms | 404 KB | n=4 |
5 | Correct | 2 ms | 404 KB | n=4 |
6 | Correct | 1 ms | 404 KB | n=2 |
7 | Correct | 2 ms | 404 KB | n=5 |
8 | Incorrect | 2 ms | 464 KB | Same heap occurs twice |
9 | Halted | 0 ms | 0 KB | - |