# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
789207 | 2023-07-21T07:41:53 Z | 반딧불(#10041) | Cookies (JOI23_cookies) | C++17 | 1000 ms | 616 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, k, t; int a[15002], b[15002]; int arr[15]; bool good[1<<15]; int DP[1<<15], track[1<<15]; int main(){ scanf("%d", &n); for(int i=1; i<=n; i++){ scanf("%d", &a[i]); for(int c=0; c<a[i]; c++) arr[t++] = i; } scanf("%d", &k); for(int i=1; i<=k; i++){ int x; scanf("%d", &x); b[x] = 1; } n=t; for(int i=0; i<(1<<n); i++){ set<int> st; int cnt = 0; for(int j=0; j<n; j++){ if((i>>j)&1){ st.insert(arr[j]); cnt++; } } if((int)st.size() == cnt && b[cnt]) good[i] = 1; } for(int i=1; i<(1<<n); i++){ DP[i] = 1e9; for(int j=i; j; j=(j-1)&i){ if(good[j] && DP[i] > DP[i^j] + 1) DP[i] = DP[i^j] + 1, track[i] = j; } } if(DP[(1<<n)-1] == 1e9){ puts("-1"); return 0; } vector<vector<int> > ans; int x = (1<<n)-1; while(x){ int t = track[x]; ans.push_back(vector<int> ()); for(int i=0; i<n; i++) if((t>>i)&1) ans.back().push_back(arr[i]); x ^= t; } printf("%d\n", (int)ans.size()); for(auto p: ans){ printf("%d ", (int)p.size()); for(auto x: p) printf("%d ", x); puts(""); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 304 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Execution timed out | 1062 ms | 364 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 468 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Execution timed out | 1091 ms | 376 KB | Time limit exceeded |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 19 ms | 468 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 308 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 17 ms | 468 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 316 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 18 ms | 516 KB | Output is correct |
16 | Correct | 19 ms | 564 KB | Output is correct |
17 | Correct | 19 ms | 596 KB | Output is correct |
18 | Correct | 20 ms | 488 KB | Output is correct |
19 | Correct | 20 ms | 560 KB | Output is correct |
20 | Correct | 24 ms | 548 KB | Output is correct |
21 | Correct | 10 ms | 444 KB | Output is correct |
22 | Correct | 22 ms | 468 KB | Output is correct |
23 | Correct | 21 ms | 560 KB | Output is correct |
24 | Correct | 21 ms | 552 KB | Output is correct |
25 | Correct | 22 ms | 472 KB | Output is correct |
26 | Correct | 22 ms | 468 KB | Output is correct |
27 | Correct | 22 ms | 552 KB | Output is correct |
28 | Correct | 22 ms | 596 KB | Output is correct |
29 | Correct | 27 ms | 560 KB | Output is correct |
30 | Correct | 22 ms | 596 KB | Output is correct |
31 | Correct | 25 ms | 572 KB | Output is correct |
32 | Correct | 26 ms | 616 KB | Output is correct |
33 | Correct | 20 ms | 568 KB | Output is correct |
34 | Correct | 24 ms | 564 KB | Output is correct |
35 | Correct | 26 ms | 564 KB | Output is correct |
36 | Correct | 25 ms | 480 KB | Output is correct |
37 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 304 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Execution timed out | 1062 ms | 364 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 304 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Execution timed out | 1062 ms | 364 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 304 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Execution timed out | 1062 ms | 364 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |