# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
836877 | 2023-08-24T16:37:29 Z | alvingogo | Cookies (JOI23_cookies) | C++14 | 129 ms | 244384 KB |
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #define AquA cin.tie(0);ios_base::sync_with_stdio(0); #define fs first #define sc second #define p_q priority_queue using namespace std; int main(){ AquA; int n; cin >> n; vector<int> a(n); int s=0; const int gd=15005; vector<int> c(gd); for(int i=0;i<n;i++){ cin >> a[i]; c[a[i]]++; s+=a[i]; } for(int i=gd-2;i>=1;i--){ c[i]+=c[i+1]; } for(int i=2;i<gd;i++){ c[i]+=c[i-1]; } int m; cin >> m; vector<int> b(m+1); for(int i=1;i<=m;i++){ cin >> b[i]; } vector<vector<bitset<gd> > > bt(gd+1); vector<bitset<gd> > lp(gd); for(int i=1;i<gd;i++){ lp[i]|=lp[i-1]; for(int j=c[i-1]+1;j<=c[i];j++){ lp[i][j]=1; } } bt[0].resize(m+1); bt[0][0][0]=1; for(int i=0;i<gd;i++){ for(int j=0;j+1<bt[i].size();j++){ bt[i][j+1]|=bt[i][j]; } int cnt=0; for(int j=1;j<=m && (i+1)*b[j]<gd;j++){ cnt=j; } bt[i+1].resize(cnt+1); for(int j=1;j<bt[i+1].size();j++){ bt[i+1][j]|=(bt[i][j]<<b[j])&lp[i+1]; } } for(int i=0;i<gd;i++){ for(int j=0;j<bt[i].size();j++){ if(bt[i][j][s]){ vector<int> k; while(i>0 && j>0){ if(i>0 && s-b[j]>=0 && bt[i-1][j][s-b[j]]){ k.push_back(b[j]); s-=b[j]; i--; } else{ j--; } } assert(i==0); p_q<pair<int,int> > pq; for(int f=0;f<n;f++){ pq.push({a[f],f}); } cout << k.size() << "\n"; for(auto h:k){ vector<pair<int,int> > d; cout << h << ' '; for(int p=0;p<h;p++){ d.push_back(pq.top()); pq.pop(); } for(auto z:d){ pq.push({z.fs-1,z.sc}); cout << z.sc+1 << " "; } cout << "\n"; } return 0; } } } cout << -1 << "\n"; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 54 ms | 106676 KB | Output is correct |
2 | Correct | 42 ms | 83704 KB | Output is correct |
3 | Correct | 41 ms | 83692 KB | Output is correct |
4 | Correct | 32 ms | 69924 KB | Output is correct |
5 | Correct | 50 ms | 97496 KB | Output is correct |
6 | Correct | 38 ms | 79052 KB | Output is correct |
7 | Correct | 49 ms | 96108 KB | Output is correct |
8 | Correct | 44 ms | 83744 KB | Output is correct |
9 | Correct | 24 ms | 56108 KB | Output is correct |
10 | Correct | 129 ms | 244384 KB | Output is correct |
11 | Correct | 35 ms | 75348 KB | Output is correct |
12 | Correct | 77 ms | 150392 KB | Output is correct |
13 | Correct | 39 ms | 79624 KB | Output is correct |
14 | Correct | 40 ms | 83128 KB | Output is correct |
15 | Correct | 38 ms | 80596 KB | Output is correct |
16 | Correct | 40 ms | 80688 KB | Output is correct |
17 | Correct | 30 ms | 64528 KB | Output is correct |
18 | Correct | 49 ms | 81328 KB | Output is correct |
19 | Correct | 31 ms | 60716 KB | Output is correct |
20 | Correct | 25 ms | 57560 KB | Output is correct |
21 | Correct | 40 ms | 81756 KB | Output is correct |
22 | Correct | 72 ms | 140580 KB | Output is correct |
23 | Correct | 65 ms | 126844 KB | Output is correct |
24 | Correct | 47 ms | 90724 KB | Output is correct |
25 | Correct | 44 ms | 90048 KB | Output is correct |
26 | Correct | 29 ms | 63488 KB | Output is correct |
27 | Correct | 28 ms | 62632 KB | Output is correct |
28 | Correct | 36 ms | 72720 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 62956 KB | Output is correct |
2 | Correct | 43 ms | 83656 KB | Output is correct |
3 | Correct | 44 ms | 83696 KB | Output is correct |
4 | Correct | 32 ms | 69784 KB | Output is correct |
5 | Correct | 43 ms | 83720 KB | Output is correct |
6 | Correct | 25 ms | 56124 KB | Output is correct |
7 | Correct | 43 ms | 83740 KB | Output is correct |
8 | Correct | 42 ms | 83696 KB | Output is correct |
9 | Correct | 43 ms | 83704 KB | Output is correct |
10 | Correct | 46 ms | 83976 KB | Output is correct |
11 | Correct | 42 ms | 83744 KB | Output is correct |
12 | Correct | 34 ms | 69868 KB | Output is correct |
13 | Correct | 34 ms | 69908 KB | Output is correct |
14 | Correct | 31 ms | 65268 KB | Output is correct |
15 | Correct | 33 ms | 69880 KB | Output is correct |
16 | Correct | 29 ms | 58816 KB | Output is correct |
17 | Correct | 26 ms | 58824 KB | Output is correct |
18 | Correct | 31 ms | 62980 KB | Output is correct |
19 | Correct | 33 ms | 65340 KB | Output is correct |
20 | Correct | 26 ms | 56404 KB | Output is correct |
21 | Correct | 26 ms | 56200 KB | Output is correct |
22 | Correct | 26 ms | 56300 KB | Output is correct |
23 | Correct | 24 ms | 56124 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 55 ms | 106720 KB | Output is correct |
2 | Correct | 28 ms | 62932 KB | Output is correct |
3 | Correct | 43 ms | 83752 KB | Output is correct |
4 | Correct | 42 ms | 83644 KB | Output is correct |
5 | Correct | 33 ms | 69892 KB | Output is correct |
6 | Correct | 51 ms | 97448 KB | Output is correct |
7 | Correct | 40 ms | 79044 KB | Output is correct |
8 | Correct | 52 ms | 96184 KB | Output is correct |
9 | Correct | 45 ms | 83720 KB | Output is correct |
10 | Correct | 43 ms | 83688 KB | Output is correct |
11 | Correct | 35 ms | 69864 KB | Output is correct |
12 | Correct | 33 ms | 69820 KB | Output is correct |
13 | Correct | 30 ms | 65248 KB | Output is correct |
14 | Correct | 34 ms | 69788 KB | Output is correct |
15 | Correct | 50 ms | 97472 KB | Output is correct |
16 | Correct | 40 ms | 79016 KB | Output is correct |
17 | Correct | 56 ms | 106652 KB | Output is correct |
18 | Correct | 34 ms | 72148 KB | Output is correct |
19 | Correct | 51 ms | 99728 KB | Output is correct |
20 | Correct | 42 ms | 85948 KB | Output is correct |
21 | Correct | 42 ms | 82304 KB | Output is correct |
22 | Correct | 38 ms | 77684 KB | Output is correct |
23 | Incorrect | 40 ms | 82280 KB | Number of cookies does not match with A_i |
24 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 54 ms | 106676 KB | Output is correct |
2 | Correct | 42 ms | 83704 KB | Output is correct |
3 | Correct | 41 ms | 83692 KB | Output is correct |
4 | Correct | 32 ms | 69924 KB | Output is correct |
5 | Correct | 50 ms | 97496 KB | Output is correct |
6 | Correct | 38 ms | 79052 KB | Output is correct |
7 | Correct | 49 ms | 96108 KB | Output is correct |
8 | Correct | 44 ms | 83744 KB | Output is correct |
9 | Correct | 24 ms | 56108 KB | Output is correct |
10 | Correct | 129 ms | 244384 KB | Output is correct |
11 | Correct | 35 ms | 75348 KB | Output is correct |
12 | Correct | 77 ms | 150392 KB | Output is correct |
13 | Correct | 39 ms | 79624 KB | Output is correct |
14 | Correct | 40 ms | 83128 KB | Output is correct |
15 | Correct | 38 ms | 80596 KB | Output is correct |
16 | Correct | 40 ms | 80688 KB | Output is correct |
17 | Correct | 30 ms | 64528 KB | Output is correct |
18 | Correct | 49 ms | 81328 KB | Output is correct |
19 | Correct | 31 ms | 60716 KB | Output is correct |
20 | Correct | 25 ms | 57560 KB | Output is correct |
21 | Correct | 40 ms | 81756 KB | Output is correct |
22 | Correct | 72 ms | 140580 KB | Output is correct |
23 | Correct | 65 ms | 126844 KB | Output is correct |
24 | Correct | 47 ms | 90724 KB | Output is correct |
25 | Correct | 44 ms | 90048 KB | Output is correct |
26 | Correct | 29 ms | 63488 KB | Output is correct |
27 | Correct | 28 ms | 62632 KB | Output is correct |
28 | Correct | 36 ms | 72720 KB | Output is correct |
29 | Correct | 55 ms | 106720 KB | Output is correct |
30 | Correct | 28 ms | 62932 KB | Output is correct |
31 | Correct | 43 ms | 83752 KB | Output is correct |
32 | Correct | 42 ms | 83644 KB | Output is correct |
33 | Correct | 33 ms | 69892 KB | Output is correct |
34 | Correct | 51 ms | 97448 KB | Output is correct |
35 | Correct | 40 ms | 79044 KB | Output is correct |
36 | Correct | 52 ms | 96184 KB | Output is correct |
37 | Correct | 45 ms | 83720 KB | Output is correct |
38 | Correct | 43 ms | 83688 KB | Output is correct |
39 | Correct | 35 ms | 69864 KB | Output is correct |
40 | Correct | 33 ms | 69820 KB | Output is correct |
41 | Correct | 30 ms | 65248 KB | Output is correct |
42 | Correct | 34 ms | 69788 KB | Output is correct |
43 | Correct | 50 ms | 97472 KB | Output is correct |
44 | Correct | 40 ms | 79016 KB | Output is correct |
45 | Correct | 56 ms | 106652 KB | Output is correct |
46 | Correct | 34 ms | 72148 KB | Output is correct |
47 | Correct | 51 ms | 99728 KB | Output is correct |
48 | Correct | 42 ms | 85948 KB | Output is correct |
49 | Correct | 42 ms | 82304 KB | Output is correct |
50 | Correct | 38 ms | 77684 KB | Output is correct |
51 | Incorrect | 40 ms | 82280 KB | Number of cookies does not match with A_i |
52 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 54 ms | 106676 KB | Output is correct |
2 | Correct | 42 ms | 83704 KB | Output is correct |
3 | Correct | 41 ms | 83692 KB | Output is correct |
4 | Correct | 32 ms | 69924 KB | Output is correct |
5 | Correct | 50 ms | 97496 KB | Output is correct |
6 | Correct | 38 ms | 79052 KB | Output is correct |
7 | Correct | 49 ms | 96108 KB | Output is correct |
8 | Correct | 44 ms | 83744 KB | Output is correct |
9 | Correct | 24 ms | 56108 KB | Output is correct |
10 | Correct | 129 ms | 244384 KB | Output is correct |
11 | Correct | 35 ms | 75348 KB | Output is correct |
12 | Correct | 77 ms | 150392 KB | Output is correct |
13 | Correct | 39 ms | 79624 KB | Output is correct |
14 | Correct | 40 ms | 83128 KB | Output is correct |
15 | Correct | 38 ms | 80596 KB | Output is correct |
16 | Correct | 40 ms | 80688 KB | Output is correct |
17 | Correct | 30 ms | 64528 KB | Output is correct |
18 | Correct | 49 ms | 81328 KB | Output is correct |
19 | Correct | 31 ms | 60716 KB | Output is correct |
20 | Correct | 25 ms | 57560 KB | Output is correct |
21 | Correct | 40 ms | 81756 KB | Output is correct |
22 | Correct | 72 ms | 140580 KB | Output is correct |
23 | Correct | 65 ms | 126844 KB | Output is correct |
24 | Correct | 47 ms | 90724 KB | Output is correct |
25 | Correct | 44 ms | 90048 KB | Output is correct |
26 | Correct | 29 ms | 63488 KB | Output is correct |
27 | Correct | 28 ms | 62632 KB | Output is correct |
28 | Correct | 36 ms | 72720 KB | Output is correct |
29 | Correct | 55 ms | 106720 KB | Output is correct |
30 | Correct | 28 ms | 62932 KB | Output is correct |
31 | Correct | 43 ms | 83752 KB | Output is correct |
32 | Correct | 42 ms | 83644 KB | Output is correct |
33 | Correct | 33 ms | 69892 KB | Output is correct |
34 | Correct | 51 ms | 97448 KB | Output is correct |
35 | Correct | 40 ms | 79044 KB | Output is correct |
36 | Correct | 52 ms | 96184 KB | Output is correct |
37 | Correct | 45 ms | 83720 KB | Output is correct |
38 | Correct | 43 ms | 83688 KB | Output is correct |
39 | Correct | 35 ms | 69864 KB | Output is correct |
40 | Correct | 33 ms | 69820 KB | Output is correct |
41 | Correct | 30 ms | 65248 KB | Output is correct |
42 | Correct | 34 ms | 69788 KB | Output is correct |
43 | Correct | 50 ms | 97472 KB | Output is correct |
44 | Correct | 40 ms | 79016 KB | Output is correct |
45 | Correct | 56 ms | 106652 KB | Output is correct |
46 | Correct | 34 ms | 72148 KB | Output is correct |
47 | Correct | 51 ms | 99728 KB | Output is correct |
48 | Correct | 42 ms | 85948 KB | Output is correct |
49 | Correct | 42 ms | 82304 KB | Output is correct |
50 | Correct | 38 ms | 77684 KB | Output is correct |
51 | Incorrect | 40 ms | 82280 KB | Number of cookies does not match with A_i |
52 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 54 ms | 106676 KB | Output is correct |
2 | Correct | 42 ms | 83704 KB | Output is correct |
3 | Correct | 41 ms | 83692 KB | Output is correct |
4 | Correct | 32 ms | 69924 KB | Output is correct |
5 | Correct | 50 ms | 97496 KB | Output is correct |
6 | Correct | 38 ms | 79052 KB | Output is correct |
7 | Correct | 49 ms | 96108 KB | Output is correct |
8 | Correct | 44 ms | 83744 KB | Output is correct |
9 | Correct | 24 ms | 56108 KB | Output is correct |
10 | Correct | 129 ms | 244384 KB | Output is correct |
11 | Correct | 35 ms | 75348 KB | Output is correct |
12 | Correct | 77 ms | 150392 KB | Output is correct |
13 | Correct | 39 ms | 79624 KB | Output is correct |
14 | Correct | 40 ms | 83128 KB | Output is correct |
15 | Correct | 38 ms | 80596 KB | Output is correct |
16 | Correct | 40 ms | 80688 KB | Output is correct |
17 | Correct | 30 ms | 64528 KB | Output is correct |
18 | Correct | 49 ms | 81328 KB | Output is correct |
19 | Correct | 31 ms | 60716 KB | Output is correct |
20 | Correct | 25 ms | 57560 KB | Output is correct |
21 | Correct | 40 ms | 81756 KB | Output is correct |
22 | Correct | 72 ms | 140580 KB | Output is correct |
23 | Correct | 65 ms | 126844 KB | Output is correct |
24 | Correct | 47 ms | 90724 KB | Output is correct |
25 | Correct | 44 ms | 90048 KB | Output is correct |
26 | Correct | 29 ms | 63488 KB | Output is correct |
27 | Correct | 28 ms | 62632 KB | Output is correct |
28 | Correct | 36 ms | 72720 KB | Output is correct |
29 | Correct | 29 ms | 62956 KB | Output is correct |
30 | Correct | 43 ms | 83656 KB | Output is correct |
31 | Correct | 44 ms | 83696 KB | Output is correct |
32 | Correct | 32 ms | 69784 KB | Output is correct |
33 | Correct | 43 ms | 83720 KB | Output is correct |
34 | Correct | 25 ms | 56124 KB | Output is correct |
35 | Correct | 43 ms | 83740 KB | Output is correct |
36 | Correct | 42 ms | 83696 KB | Output is correct |
37 | Correct | 43 ms | 83704 KB | Output is correct |
38 | Correct | 46 ms | 83976 KB | Output is correct |
39 | Correct | 42 ms | 83744 KB | Output is correct |
40 | Correct | 34 ms | 69868 KB | Output is correct |
41 | Correct | 34 ms | 69908 KB | Output is correct |
42 | Correct | 31 ms | 65268 KB | Output is correct |
43 | Correct | 33 ms | 69880 KB | Output is correct |
44 | Correct | 29 ms | 58816 KB | Output is correct |
45 | Correct | 26 ms | 58824 KB | Output is correct |
46 | Correct | 31 ms | 62980 KB | Output is correct |
47 | Correct | 33 ms | 65340 KB | Output is correct |
48 | Correct | 26 ms | 56404 KB | Output is correct |
49 | Correct | 26 ms | 56200 KB | Output is correct |
50 | Correct | 26 ms | 56300 KB | Output is correct |
51 | Correct | 24 ms | 56124 KB | Output is correct |
52 | Correct | 55 ms | 106720 KB | Output is correct |
53 | Correct | 28 ms | 62932 KB | Output is correct |
54 | Correct | 43 ms | 83752 KB | Output is correct |
55 | Correct | 42 ms | 83644 KB | Output is correct |
56 | Correct | 33 ms | 69892 KB | Output is correct |
57 | Correct | 51 ms | 97448 KB | Output is correct |
58 | Correct | 40 ms | 79044 KB | Output is correct |
59 | Correct | 52 ms | 96184 KB | Output is correct |
60 | Correct | 45 ms | 83720 KB | Output is correct |
61 | Correct | 43 ms | 83688 KB | Output is correct |
62 | Correct | 35 ms | 69864 KB | Output is correct |
63 | Correct | 33 ms | 69820 KB | Output is correct |
64 | Correct | 30 ms | 65248 KB | Output is correct |
65 | Correct | 34 ms | 69788 KB | Output is correct |
66 | Correct | 50 ms | 97472 KB | Output is correct |
67 | Correct | 40 ms | 79016 KB | Output is correct |
68 | Correct | 56 ms | 106652 KB | Output is correct |
69 | Correct | 34 ms | 72148 KB | Output is correct |
70 | Correct | 51 ms | 99728 KB | Output is correct |
71 | Correct | 42 ms | 85948 KB | Output is correct |
72 | Correct | 42 ms | 82304 KB | Output is correct |
73 | Correct | 38 ms | 77684 KB | Output is correct |
74 | Incorrect | 40 ms | 82280 KB | Number of cookies does not match with A_i |
75 | Halted | 0 ms | 0 KB | - |