# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
807249 |
2023-08-04T15:14:32 Z |
someone |
Cookies (JOI23_cookies) |
C++14 |
|
25 ms |
29628 KB |
#include <bits/stdc++.h>
//#define int long long
using namespace std;
const int N = 1.5e4 + 42;
vector<int> boite;
vector<bitset<N>> dp[N];
int n, m, a[N], sz[N], prefix[N];
void remonter(int i, int j, int sum) {
if(sum == 0)
return;
if(dp[i-1][j][sum - sz[j]]) {
boite.push_back(-sz[j]);
remonter(i-1, j, sum - sz[j]);
} else {
remonter(i, j+1, sum);
}
}
void printSol() {
vector<int> id[N];
vector<pair<int, int>> vals;
for(int i = 0; i < n; i++)
vals.push_back({-a[i], i});
sort(vals.begin(), vals.end());
for(int i = 0; i < n; i++)
for(int j = 0; j < a[vals[i].second]; j++)
id[j].push_back(vals[i].second+1);
queue<int> ids;
for(int i = 0; i < N; i++)
for(int j : id[i])
ids.push(j);
sort(boite.begin(), boite.end());
cout << boite.size() << '\n';
for(int b : boite) {
b = -b;
cout << b << ' ';
for(int j = 0; j < b; j++) {
cout << ids.front() << ' ';
ids.pop();
}
cout << '\n';
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0; i < n; i++) {
cin >> a[i];
for(int j = 0; j < N; j++)
prefix[j] += min(j, a[i]);
}
cin >> m;
dp[0].resize(m);
dp[0][m-1] = true;
for(int i = 0; i < m; i++)
cin >> sz[i];
int sum = prefix[N-1];
for(int i = 0; i <= sum; i++) {
for(int j = m-1; j >= 0; j--)
if(i * sz[j] <= sum) {
dp[i+1].resize(j+1);
j = 0;
}
for(int j = m-1; j >= 0; j--)
if(i * sz[j] <= sum) {
dp[i][j] <<= (N-prefix[i]-1);
dp[i][j] >>= (N-prefix[i]-1);
if(dp[i][j][sum]) {
remonter(i, j, sum);
printSol();
return 0;
}
if(j > 0)
dp[i][j-1] |= dp[i][j];
if((i+1) * sz[j] <= sum)
dp[i+1][j] |= (dp[i][j] << sz[j]);
}
}
cout << -1 << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
7 ms |
2004 KB |
Output is correct |
9 |
Correct |
6 ms |
1108 KB |
Output is correct |
10 |
Correct |
8 ms |
4324 KB |
Output is correct |
11 |
Correct |
7 ms |
2024 KB |
Output is correct |
12 |
Correct |
7 ms |
2132 KB |
Output is correct |
13 |
Correct |
7 ms |
2260 KB |
Output is correct |
14 |
Correct |
7 ms |
2644 KB |
Output is correct |
15 |
Correct |
7 ms |
2516 KB |
Output is correct |
16 |
Correct |
7 ms |
2652 KB |
Output is correct |
17 |
Correct |
6 ms |
1236 KB |
Output is correct |
18 |
Correct |
7 ms |
1364 KB |
Output is correct |
19 |
Correct |
6 ms |
1108 KB |
Output is correct |
20 |
Correct |
6 ms |
1108 KB |
Output is correct |
21 |
Correct |
6 ms |
1748 KB |
Output is correct |
22 |
Correct |
8 ms |
4196 KB |
Output is correct |
23 |
Correct |
8 ms |
3796 KB |
Output is correct |
24 |
Correct |
6 ms |
1380 KB |
Output is correct |
25 |
Correct |
6 ms |
1372 KB |
Output is correct |
26 |
Correct |
7 ms |
1384 KB |
Output is correct |
27 |
Correct |
6 ms |
1384 KB |
Output is correct |
28 |
Correct |
7 ms |
2004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
7 ms |
2020 KB |
Output is correct |
6 |
Correct |
6 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
2004 KB |
Output is correct |
9 |
Correct |
5 ms |
6816 KB |
Output is correct |
10 |
Correct |
25 ms |
29628 KB |
Output is correct |
11 |
Correct |
1 ms |
980 KB |
Output is correct |
12 |
Correct |
0 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
1108 KB |
Output is correct |
14 |
Correct |
1 ms |
680 KB |
Output is correct |
15 |
Correct |
1 ms |
1060 KB |
Output is correct |
16 |
Incorrect |
1 ms |
1108 KB |
the types of the cookies in it should be different |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1064 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Incorrect |
1 ms |
1108 KB |
the types of the cookies in it should be different |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
7 ms |
2004 KB |
Output is correct |
9 |
Correct |
6 ms |
1108 KB |
Output is correct |
10 |
Correct |
8 ms |
4324 KB |
Output is correct |
11 |
Correct |
7 ms |
2024 KB |
Output is correct |
12 |
Correct |
7 ms |
2132 KB |
Output is correct |
13 |
Correct |
7 ms |
2260 KB |
Output is correct |
14 |
Correct |
7 ms |
2644 KB |
Output is correct |
15 |
Correct |
7 ms |
2516 KB |
Output is correct |
16 |
Correct |
7 ms |
2652 KB |
Output is correct |
17 |
Correct |
6 ms |
1236 KB |
Output is correct |
18 |
Correct |
7 ms |
1364 KB |
Output is correct |
19 |
Correct |
6 ms |
1108 KB |
Output is correct |
20 |
Correct |
6 ms |
1108 KB |
Output is correct |
21 |
Correct |
6 ms |
1748 KB |
Output is correct |
22 |
Correct |
8 ms |
4196 KB |
Output is correct |
23 |
Correct |
8 ms |
3796 KB |
Output is correct |
24 |
Correct |
6 ms |
1380 KB |
Output is correct |
25 |
Correct |
6 ms |
1372 KB |
Output is correct |
26 |
Correct |
7 ms |
1384 KB |
Output is correct |
27 |
Correct |
6 ms |
1384 KB |
Output is correct |
28 |
Correct |
7 ms |
2004 KB |
Output is correct |
29 |
Correct |
1 ms |
1112 KB |
Output is correct |
30 |
Correct |
1 ms |
724 KB |
Output is correct |
31 |
Correct |
1 ms |
980 KB |
Output is correct |
32 |
Correct |
1 ms |
980 KB |
Output is correct |
33 |
Correct |
1 ms |
980 KB |
Output is correct |
34 |
Correct |
1 ms |
980 KB |
Output is correct |
35 |
Correct |
1 ms |
980 KB |
Output is correct |
36 |
Correct |
1 ms |
1108 KB |
Output is correct |
37 |
Correct |
1 ms |
1108 KB |
Output is correct |
38 |
Correct |
1 ms |
980 KB |
Output is correct |
39 |
Correct |
1 ms |
724 KB |
Output is correct |
40 |
Correct |
1 ms |
1108 KB |
Output is correct |
41 |
Correct |
1 ms |
724 KB |
Output is correct |
42 |
Correct |
1 ms |
1108 KB |
Output is correct |
43 |
Correct |
1 ms |
1064 KB |
Output is correct |
44 |
Correct |
1 ms |
1108 KB |
Output is correct |
45 |
Correct |
1 ms |
1108 KB |
Output is correct |
46 |
Incorrect |
1 ms |
1108 KB |
the types of the cookies in it should be different |
47 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
7 ms |
2004 KB |
Output is correct |
9 |
Correct |
6 ms |
1108 KB |
Output is correct |
10 |
Correct |
8 ms |
4324 KB |
Output is correct |
11 |
Correct |
7 ms |
2024 KB |
Output is correct |
12 |
Correct |
7 ms |
2132 KB |
Output is correct |
13 |
Correct |
7 ms |
2260 KB |
Output is correct |
14 |
Correct |
7 ms |
2644 KB |
Output is correct |
15 |
Correct |
7 ms |
2516 KB |
Output is correct |
16 |
Correct |
7 ms |
2652 KB |
Output is correct |
17 |
Correct |
6 ms |
1236 KB |
Output is correct |
18 |
Correct |
7 ms |
1364 KB |
Output is correct |
19 |
Correct |
6 ms |
1108 KB |
Output is correct |
20 |
Correct |
6 ms |
1108 KB |
Output is correct |
21 |
Correct |
6 ms |
1748 KB |
Output is correct |
22 |
Correct |
8 ms |
4196 KB |
Output is correct |
23 |
Correct |
8 ms |
3796 KB |
Output is correct |
24 |
Correct |
6 ms |
1380 KB |
Output is correct |
25 |
Correct |
6 ms |
1372 KB |
Output is correct |
26 |
Correct |
7 ms |
1384 KB |
Output is correct |
27 |
Correct |
6 ms |
1384 KB |
Output is correct |
28 |
Correct |
7 ms |
2004 KB |
Output is correct |
29 |
Correct |
1 ms |
1112 KB |
Output is correct |
30 |
Correct |
1 ms |
724 KB |
Output is correct |
31 |
Correct |
1 ms |
980 KB |
Output is correct |
32 |
Correct |
1 ms |
980 KB |
Output is correct |
33 |
Correct |
1 ms |
980 KB |
Output is correct |
34 |
Correct |
1 ms |
980 KB |
Output is correct |
35 |
Correct |
1 ms |
980 KB |
Output is correct |
36 |
Correct |
1 ms |
1108 KB |
Output is correct |
37 |
Correct |
1 ms |
1108 KB |
Output is correct |
38 |
Correct |
1 ms |
980 KB |
Output is correct |
39 |
Correct |
1 ms |
724 KB |
Output is correct |
40 |
Correct |
1 ms |
1108 KB |
Output is correct |
41 |
Correct |
1 ms |
724 KB |
Output is correct |
42 |
Correct |
1 ms |
1108 KB |
Output is correct |
43 |
Correct |
1 ms |
1064 KB |
Output is correct |
44 |
Correct |
1 ms |
1108 KB |
Output is correct |
45 |
Correct |
1 ms |
1108 KB |
Output is correct |
46 |
Incorrect |
1 ms |
1108 KB |
the types of the cookies in it should be different |
47 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
7 ms |
2004 KB |
Output is correct |
9 |
Correct |
6 ms |
1108 KB |
Output is correct |
10 |
Correct |
8 ms |
4324 KB |
Output is correct |
11 |
Correct |
7 ms |
2024 KB |
Output is correct |
12 |
Correct |
7 ms |
2132 KB |
Output is correct |
13 |
Correct |
7 ms |
2260 KB |
Output is correct |
14 |
Correct |
7 ms |
2644 KB |
Output is correct |
15 |
Correct |
7 ms |
2516 KB |
Output is correct |
16 |
Correct |
7 ms |
2652 KB |
Output is correct |
17 |
Correct |
6 ms |
1236 KB |
Output is correct |
18 |
Correct |
7 ms |
1364 KB |
Output is correct |
19 |
Correct |
6 ms |
1108 KB |
Output is correct |
20 |
Correct |
6 ms |
1108 KB |
Output is correct |
21 |
Correct |
6 ms |
1748 KB |
Output is correct |
22 |
Correct |
8 ms |
4196 KB |
Output is correct |
23 |
Correct |
8 ms |
3796 KB |
Output is correct |
24 |
Correct |
6 ms |
1380 KB |
Output is correct |
25 |
Correct |
6 ms |
1372 KB |
Output is correct |
26 |
Correct |
7 ms |
1384 KB |
Output is correct |
27 |
Correct |
6 ms |
1384 KB |
Output is correct |
28 |
Correct |
7 ms |
2004 KB |
Output is correct |
29 |
Correct |
1 ms |
724 KB |
Output is correct |
30 |
Correct |
1 ms |
980 KB |
Output is correct |
31 |
Correct |
1 ms |
980 KB |
Output is correct |
32 |
Correct |
1 ms |
980 KB |
Output is correct |
33 |
Correct |
7 ms |
2020 KB |
Output is correct |
34 |
Correct |
6 ms |
1108 KB |
Output is correct |
35 |
Correct |
1 ms |
1108 KB |
Output is correct |
36 |
Correct |
1 ms |
2004 KB |
Output is correct |
37 |
Correct |
5 ms |
6816 KB |
Output is correct |
38 |
Correct |
25 ms |
29628 KB |
Output is correct |
39 |
Correct |
1 ms |
980 KB |
Output is correct |
40 |
Correct |
0 ms |
724 KB |
Output is correct |
41 |
Correct |
1 ms |
1108 KB |
Output is correct |
42 |
Correct |
1 ms |
680 KB |
Output is correct |
43 |
Correct |
1 ms |
1060 KB |
Output is correct |
44 |
Incorrect |
1 ms |
1108 KB |
the types of the cookies in it should be different |
45 |
Halted |
0 ms |
0 KB |
- |