# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
789320 |
2023-07-21T09:12:43 Z |
이동현(#10044) |
Cookies (JOI23_cookies) |
C++17 |
|
161 ms |
2496 KB |
#include <bits/stdc++.h>
#define int long long
#define mi(x, y) (x = min(x, y))
#define ma(x, y) (x = max(x, y))
using namespace std;
const int NS = 15004;
const int SZ = 504;
int n, m;
int a[NS], b[NS];
int mn[NS];
bitset<504> dp[NS][SZ];
pair<int, int> srt[NS];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
int asum = 0;
for(int i = 1; i <= n; ++i){
cin >> a[i];
srt[i] = {a[i], i};
asum += a[i];
}
cin >> m;
for(int i = 1; i <= m; ++i){
cin >> b[i];
}
sort(b + 1, b + m + 1);
reverse(b + 1, b + m + 1);
for(int i = 1; i <= SZ - 4; ++i){
for(int j = 1; j <= n; ++j){
mn[i] += min(i, a[j]);
}
mn[i] = min(mn[i], 500ll);
}
dp[0][0][0] = 1;
for(int i = 1; i <= m; ++i){
for(int j = 0; j <= SZ - 4; ++j){
for(int k = 0; k <= mn[j]; ++k){
if(dp[i - 1][j][k]){
dp[i][j][k] = 1;
}
if(j && k >= b[i] && dp[i][j - 1][k - b[i]]){
dp[i][j][k] = 1;
}
}
}
}
int ans = -1;
for(int i = 1; i <= SZ - 4; ++i){
if(dp[m][i][asum]){
ans = i;
break;
}
}
cout << ans << '\n';
if(ans == -1){
return 0;
}
vector<int> lst;
auto makelst = [&](auto&&self, int i, int j, int k)->void{
if(!i) return;
if(dp[i - 1][j][k]){
self(self, i - 1, j, k);
}
else{
self(self, i, j - 1, k - b[i]);
lst.push_back(b[i]);
}
};
makelst(makelst, m, ans, asum);
for(auto&i:lst){
cout << i << ' ';
sort(srt + 1, srt + n + 1);
reverse(srt + 1, srt + n + 1);
while(!srt[n].first){
--n;
}
for(int j = 1; j <= i; ++j){
assert(srt[j].first >= 1);
--srt[j].first;
cout << srt[j].second << ' ';
}
cout << '\n';
}
assert(srt[0].first == 0);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
161 ms |
2496 KB |
Output is correct |
11 |
Correct |
77 ms |
1344 KB |
Output is correct |
12 |
Correct |
18 ms |
596 KB |
Output is correct |
13 |
Correct |
39 ms |
764 KB |
Output is correct |
14 |
Correct |
67 ms |
1200 KB |
Output is correct |
15 |
Correct |
65 ms |
1228 KB |
Output is correct |
16 |
Correct |
74 ms |
1340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
4 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
340 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
32 ms |
724 KB |
Output is correct |
22 |
Correct |
82 ms |
1364 KB |
Output is correct |
23 |
Correct |
82 ms |
1368 KB |
Output is correct |
24 |
Correct |
10 ms |
468 KB |
Output is correct |
25 |
Correct |
10 ms |
468 KB |
Output is correct |
26 |
Correct |
10 ms |
468 KB |
Output is correct |
27 |
Correct |
10 ms |
468 KB |
Output is correct |
28 |
Correct |
46 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Incorrect |
1 ms |
340 KB |
Number of cookies does not match with A_i |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
161 ms |
2496 KB |
Output is correct |
11 |
Correct |
77 ms |
1344 KB |
Output is correct |
12 |
Correct |
18 ms |
596 KB |
Output is correct |
13 |
Correct |
39 ms |
764 KB |
Output is correct |
14 |
Correct |
67 ms |
1200 KB |
Output is correct |
15 |
Correct |
65 ms |
1228 KB |
Output is correct |
16 |
Correct |
74 ms |
1340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
4 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
340 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
32 ms |
724 KB |
Output is correct |
22 |
Correct |
82 ms |
1364 KB |
Output is correct |
23 |
Correct |
82 ms |
1368 KB |
Output is correct |
24 |
Correct |
10 ms |
468 KB |
Output is correct |
25 |
Correct |
10 ms |
468 KB |
Output is correct |
26 |
Correct |
10 ms |
468 KB |
Output is correct |
27 |
Correct |
10 ms |
468 KB |
Output is correct |
28 |
Correct |
46 ms |
844 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
0 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
0 ms |
340 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
0 ms |
340 KB |
Output is correct |
45 |
Correct |
0 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
0 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
0 ms |
340 KB |
Output is correct |
51 |
Correct |
0 ms |
340 KB |
Output is correct |
52 |
Correct |
0 ms |
340 KB |
Output is correct |
53 |
Correct |
0 ms |
340 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
0 ms |
340 KB |
Output is correct |
56 |
Correct |
0 ms |
340 KB |
Output is correct |
57 |
Correct |
0 ms |
340 KB |
Output is correct |
58 |
Correct |
0 ms |
340 KB |
Output is correct |
59 |
Correct |
0 ms |
340 KB |
Output is correct |
60 |
Correct |
0 ms |
340 KB |
Output is correct |
61 |
Correct |
0 ms |
340 KB |
Output is correct |
62 |
Correct |
0 ms |
340 KB |
Output is correct |
63 |
Correct |
0 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Correct |
0 ms |
340 KB |
Output is correct |
66 |
Correct |
0 ms |
340 KB |
Output is correct |
67 |
Correct |
1 ms |
340 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
340 KB |
Output is correct |
70 |
Correct |
8 ms |
432 KB |
Output is correct |
71 |
Correct |
6 ms |
340 KB |
Output is correct |
72 |
Correct |
7 ms |
340 KB |
Output is correct |
73 |
Correct |
5 ms |
364 KB |
Output is correct |
74 |
Correct |
4 ms |
340 KB |
Output is correct |
75 |
Correct |
6 ms |
340 KB |
Output is correct |
76 |
Correct |
6 ms |
340 KB |
Output is correct |
77 |
Correct |
4 ms |
340 KB |
Output is correct |
78 |
Correct |
4 ms |
340 KB |
Output is correct |
79 |
Correct |
3 ms |
340 KB |
Output is correct |
80 |
Correct |
2 ms |
340 KB |
Output is correct |
81 |
Correct |
2 ms |
340 KB |
Output is correct |
82 |
Correct |
6 ms |
340 KB |
Output is correct |
83 |
Correct |
3 ms |
372 KB |
Output is correct |
84 |
Correct |
18 ms |
520 KB |
Output is correct |
85 |
Correct |
4 ms |
396 KB |
Output is correct |
86 |
Correct |
9 ms |
504 KB |
Output is correct |
87 |
Correct |
9 ms |
404 KB |
Output is correct |
88 |
Correct |
8 ms |
468 KB |
Output is correct |
89 |
Correct |
9 ms |
468 KB |
Output is correct |
90 |
Correct |
9 ms |
468 KB |
Output is correct |
91 |
Correct |
8 ms |
496 KB |
Output is correct |
92 |
Correct |
19 ms |
604 KB |
Output is correct |
93 |
Correct |
144 ms |
2272 KB |
Output is correct |
94 |
Correct |
77 ms |
1400 KB |
Output is correct |
95 |
Correct |
6 ms |
468 KB |
Output is correct |
96 |
Correct |
3 ms |
340 KB |
Output is correct |
97 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
161 ms |
2496 KB |
Output is correct |
11 |
Correct |
77 ms |
1344 KB |
Output is correct |
12 |
Correct |
18 ms |
596 KB |
Output is correct |
13 |
Correct |
39 ms |
764 KB |
Output is correct |
14 |
Correct |
67 ms |
1200 KB |
Output is correct |
15 |
Correct |
65 ms |
1228 KB |
Output is correct |
16 |
Correct |
74 ms |
1340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
4 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
340 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
32 ms |
724 KB |
Output is correct |
22 |
Correct |
82 ms |
1364 KB |
Output is correct |
23 |
Correct |
82 ms |
1368 KB |
Output is correct |
24 |
Correct |
10 ms |
468 KB |
Output is correct |
25 |
Correct |
10 ms |
468 KB |
Output is correct |
26 |
Correct |
10 ms |
468 KB |
Output is correct |
27 |
Correct |
10 ms |
468 KB |
Output is correct |
28 |
Correct |
46 ms |
844 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
0 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
0 ms |
340 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
0 ms |
340 KB |
Output is correct |
45 |
Correct |
0 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
0 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
0 ms |
340 KB |
Output is correct |
51 |
Correct |
0 ms |
340 KB |
Output is correct |
52 |
Correct |
0 ms |
340 KB |
Output is correct |
53 |
Correct |
0 ms |
340 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
0 ms |
340 KB |
Output is correct |
56 |
Correct |
0 ms |
340 KB |
Output is correct |
57 |
Correct |
0 ms |
340 KB |
Output is correct |
58 |
Correct |
0 ms |
340 KB |
Output is correct |
59 |
Correct |
0 ms |
340 KB |
Output is correct |
60 |
Correct |
0 ms |
340 KB |
Output is correct |
61 |
Correct |
0 ms |
340 KB |
Output is correct |
62 |
Correct |
0 ms |
340 KB |
Output is correct |
63 |
Correct |
0 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Correct |
0 ms |
340 KB |
Output is correct |
66 |
Correct |
0 ms |
340 KB |
Output is correct |
67 |
Correct |
1 ms |
340 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
340 KB |
Output is correct |
70 |
Correct |
8 ms |
432 KB |
Output is correct |
71 |
Correct |
6 ms |
340 KB |
Output is correct |
72 |
Correct |
7 ms |
340 KB |
Output is correct |
73 |
Correct |
5 ms |
364 KB |
Output is correct |
74 |
Correct |
4 ms |
340 KB |
Output is correct |
75 |
Correct |
6 ms |
340 KB |
Output is correct |
76 |
Correct |
6 ms |
340 KB |
Output is correct |
77 |
Correct |
4 ms |
340 KB |
Output is correct |
78 |
Correct |
4 ms |
340 KB |
Output is correct |
79 |
Correct |
3 ms |
340 KB |
Output is correct |
80 |
Correct |
2 ms |
340 KB |
Output is correct |
81 |
Correct |
2 ms |
340 KB |
Output is correct |
82 |
Correct |
6 ms |
340 KB |
Output is correct |
83 |
Correct |
3 ms |
372 KB |
Output is correct |
84 |
Correct |
18 ms |
520 KB |
Output is correct |
85 |
Correct |
4 ms |
396 KB |
Output is correct |
86 |
Correct |
9 ms |
504 KB |
Output is correct |
87 |
Correct |
9 ms |
404 KB |
Output is correct |
88 |
Correct |
8 ms |
468 KB |
Output is correct |
89 |
Correct |
9 ms |
468 KB |
Output is correct |
90 |
Correct |
9 ms |
468 KB |
Output is correct |
91 |
Correct |
8 ms |
496 KB |
Output is correct |
92 |
Correct |
19 ms |
604 KB |
Output is correct |
93 |
Correct |
144 ms |
2272 KB |
Output is correct |
94 |
Correct |
77 ms |
1400 KB |
Output is correct |
95 |
Correct |
6 ms |
468 KB |
Output is correct |
96 |
Correct |
3 ms |
340 KB |
Output is correct |
97 |
Correct |
4 ms |
340 KB |
Output is correct |
98 |
Incorrect |
1 ms |
340 KB |
Number of cookies does not match with A_i |
99 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
161 ms |
2496 KB |
Output is correct |
11 |
Correct |
77 ms |
1344 KB |
Output is correct |
12 |
Correct |
18 ms |
596 KB |
Output is correct |
13 |
Correct |
39 ms |
764 KB |
Output is correct |
14 |
Correct |
67 ms |
1200 KB |
Output is correct |
15 |
Correct |
65 ms |
1228 KB |
Output is correct |
16 |
Correct |
74 ms |
1340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
4 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
340 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
32 ms |
724 KB |
Output is correct |
22 |
Correct |
82 ms |
1364 KB |
Output is correct |
23 |
Correct |
82 ms |
1368 KB |
Output is correct |
24 |
Correct |
10 ms |
468 KB |
Output is correct |
25 |
Correct |
10 ms |
468 KB |
Output is correct |
26 |
Correct |
10 ms |
468 KB |
Output is correct |
27 |
Correct |
10 ms |
468 KB |
Output is correct |
28 |
Correct |
46 ms |
844 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Incorrect |
1 ms |
340 KB |
Number of cookies does not match with A_i |
38 |
Halted |
0 ms |
0 KB |
- |