# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
790652 | 2023-07-23T04:40:01 Z | qwerasdfzxcl | Cookies (JOI23_cookies) | C++17 | 48 ms | 84596 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<bitset<15015>> dp[15015]; bitset<15015> B[15015]; int a[15015], b[15015], valid[15015], n; void output(int x, int y, int z){ vector<int> V; while(x > 0){ // printf("%d %d %d\n", x, y, z); if (y+1 < (int)dp[x].size() && dp[x][y+1][z]) y++; else{ assert(y < (int)dp[x-1].size()); assert(dp[x-1][y][z-b[y]]); V.push_back(b[y]); z -= b[y]; x--; } } assert(z==0); priority_queue<pair<int, int>> pq; for (int i=1;i<=n;i++) pq.emplace(a[i], i); vector<vector<int>> ans; for (auto &x:V){ assert((int)pq.size() >= x); ans.emplace_back(); vector<pair<int, int>> buf; for (int i=1;i<=x;i++){ ans.back().push_back(pq.top().second); if (pq.top().first > 1) buf.emplace_back(pq.top().first-1, pq.top().second); pq.pop(); } for (auto &p:buf) pq.push(p); } printf("%d\n", (int)ans.size()); for (auto &V:ans){ printf("%d ", (int)V.size()); for (auto &x:V) printf("%d ", x); printf("\n"); } exit(0); } int main(){ int S = 0; scanf("%d", &n); for (int i=1;i<=n;i++){ scanf("%d", a+i); S += a[i]; } int m; scanf("%d", &m); for (int i=1;i<=m;i++) scanf("%d", b+i); for (int i=1;i<=n;i++){ for (int j=1;j<=a[i];j++) valid[j]++; } B[0].set(0); for (int i=1;i<=S;i++){ valid[i] += valid[i-1]; for (int j=1;j<=valid[i]-valid[i-1];j++) B[i].set(j+valid[i-1]); B[i] |= B[i-1]; } for (int i=1;i<=S;i++) dp[i].resize(min(S/i, m) + 1); dp[0].resize(min(S, m)+1); dp[0][m].set(0); for (int i=1;i<=S;i++){ for (int j=(int)dp[i].size()-1;j;j--){ if (j+1 < (int)dp[i].size() && j < (int)dp[i-1].size()) dp[i][j] = dp[i][j+1] | (dp[i-1][j] << b[j]); else if (j+1 < (int)dp[i].size()) dp[i][j] = dp[i][j+1]; else if (j < (int)dp[i-1].size()) dp[i][j] = dp[i-1][j] << b[j]; dp[i][j] &= B[i]; } } for (int i=1;i<=S;i++) if (dp[i][1][S]) output(i, 1, S); printf("-1\n"); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 724 KB | Output is correct |
2 | Correct | 0 ms | 596 KB | Output is correct |
3 | Correct | 0 ms | 596 KB | Output is correct |
4 | Correct | 0 ms | 596 KB | Output is correct |
5 | Correct | 0 ms | 596 KB | Output is correct |
6 | Incorrect | 1 ms | 596 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 724 KB | Output is correct |
2 | Correct | 1 ms | 596 KB | Output is correct |
3 | Correct | 0 ms | 596 KB | Output is correct |
4 | Correct | 1 ms | 596 KB | Output is correct |
5 | Correct | 2 ms | 3412 KB | Output is correct |
6 | Correct | 2 ms | 3412 KB | Output is correct |
7 | Correct | 1 ms | 724 KB | Output is correct |
8 | Correct | 2 ms | 3412 KB | Output is correct |
9 | Correct | 10 ms | 17492 KB | Output is correct |
10 | Correct | 46 ms | 84596 KB | Output is correct |
11 | Correct | 1 ms | 596 KB | Output is correct |
12 | Correct | 1 ms | 596 KB | Output is correct |
13 | Correct | 1 ms | 724 KB | Output is correct |
14 | Correct | 1 ms | 724 KB | Output is correct |
15 | Correct | 1 ms | 660 KB | Output is correct |
16 | Correct | 2 ms | 3412 KB | Output is correct |
17 | Correct | 2 ms | 3412 KB | Output is correct |
18 | Correct | 45 ms | 83988 KB | Output is correct |
19 | Correct | 48 ms | 84112 KB | Output is correct |
20 | Correct | 46 ms | 83864 KB | Output is correct |
21 | Correct | 46 ms | 83860 KB | Output is correct |
22 | Correct | 45 ms | 82428 KB | Output is correct |
23 | Correct | 3 ms | 6164 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 724 KB | Output is correct |
2 | Correct | 1 ms | 724 KB | Output is correct |
3 | Correct | 1 ms | 596 KB | Output is correct |
4 | Correct | 0 ms | 596 KB | Output is correct |
5 | Correct | 1 ms | 596 KB | Output is correct |
6 | Correct | 0 ms | 596 KB | Output is correct |
7 | Incorrect | 0 ms | 596 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 724 KB | Output is correct |
2 | Correct | 0 ms | 596 KB | Output is correct |
3 | Correct | 0 ms | 596 KB | Output is correct |
4 | Correct | 0 ms | 596 KB | Output is correct |
5 | Correct | 0 ms | 596 KB | Output is correct |
6 | Incorrect | 1 ms | 596 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 724 KB | Output is correct |
2 | Correct | 0 ms | 596 KB | Output is correct |
3 | Correct | 0 ms | 596 KB | Output is correct |
4 | Correct | 0 ms | 596 KB | Output is correct |
5 | Correct | 0 ms | 596 KB | Output is correct |
6 | Incorrect | 1 ms | 596 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 724 KB | Output is correct |
2 | Correct | 0 ms | 596 KB | Output is correct |
3 | Correct | 0 ms | 596 KB | Output is correct |
4 | Correct | 0 ms | 596 KB | Output is correct |
5 | Correct | 0 ms | 596 KB | Output is correct |
6 | Incorrect | 1 ms | 596 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |