Submission #892023

# Submission time Handle Problem Language Result Execution time Memory
892023 2023-12-24T16:24:52 Z alexander707070 Cookies (JOI23_cookies) C++14
78 / 100
610 ms 489040 KB
#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define MAXN 3007
using namespace std;

int n,m,pt,total;
int a[MAXN],b[MAXN],ind[MAXN];

vector< pair<int,int> > v;
vector< vector<int> > w;

int maxs[MAXN],br;
vector<short> dp[MAXN][MAXN];

void calc_dp(){
    for(int sum=total;sum>=0;sum--){
        for(int box=1;box<=m;box++){
            dp[sum][box].resize(sum/b[box]+2);

            for(int pos=sum/b[box]+1;pos>=1;pos--){

                if(sum==total){
                    dp[sum][box][pos]=0;
                    continue;
                }

                dp[sum][box][pos]=3005;

                if(box>1)dp[sum][box][pos]=dp[sum][box-1][pos];

                if(sum+b[box]<=maxs[pos] and sum+b[box]<=total and dp[sum][box][pos]>dp[sum+b[box]][box][pos+1]+1){
                    dp[sum][box][pos]=dp[sum+b[box]][box][pos+1]+1;
                }
            }
        }
    }
}

void solve(int pos,int box,int sum){
    if(sum==total)return;

    if(box>1 and dp[sum][box][pos]==dp[sum][box-1][pos]){
        solve(pos,box-1,sum); return;
    }

    br++; v.push_back({b[box],br});
    solve(pos+1,box,sum+b[box]);
}

bool cmp(int x,int y){
    return a[x]>a[y];
}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        total+=a[i];
        ind[i]=i;
    }
    
    for(int i=1;i<=total;i++){
        for(int f=1;f<=n;f++){
            maxs[i]+=min(a[f],i);
        }
    }

    cin>>m;
    for(int i=1;i<=m;i++){
        cin>>b[i];
    }

    calc_dp();

    if(dp[0][m][1]>total){
        cout<<"-1\n";
        return 0;
    }

    solve(1,m,0);
    w.resize(int(v.size()));

    sort(ind+1,ind+n+1,cmp);

    for(int i=1;i<=n;i++){
        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());

        for(int f=0;f<a[ind[i]];f++){
            v[f].first--;
            w[v[f].second-1].push_back(ind[i]);
        }
    }

    cout<<w.size()<<"\n";
    for(int i=0;i<w.size();i++){
        cout<<w[i].size()<<" ";
        for(int f:w[i])cout<<f<<" ";
        cout<<"\n";
    }

    return 0;
}

Compilation message

cookies.cpp: In function 'int main()':
cookies.cpp:102:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |     for(int i=0;i<w.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 62 ms 212560 KB Output is correct
2 Correct 48 ms 212560 KB Output is correct
3 Correct 46 ms 212568 KB Output is correct
4 Correct 48 ms 212816 KB Output is correct
5 Correct 45 ms 212564 KB Output is correct
6 Correct 47 ms 212564 KB Output is correct
7 Correct 45 ms 212572 KB Output is correct
8 Correct 51 ms 213076 KB Output is correct
9 Correct 45 ms 212816 KB Output is correct
10 Correct 61 ms 221204 KB Output is correct
11 Correct 52 ms 216660 KB Output is correct
12 Correct 49 ms 213856 KB Output is correct
13 Correct 50 ms 214696 KB Output is correct
14 Correct 53 ms 216336 KB Output is correct
15 Correct 53 ms 216044 KB Output is correct
16 Correct 53 ms 216668 KB Output is correct
17 Correct 46 ms 212844 KB Output is correct
18 Correct 46 ms 213076 KB Output is correct
19 Correct 47 ms 212828 KB Output is correct
20 Correct 46 ms 212940 KB Output is correct
21 Correct 50 ms 214204 KB Output is correct
22 Correct 59 ms 217172 KB Output is correct
23 Correct 53 ms 216660 KB Output is correct
24 Correct 47 ms 213332 KB Output is correct
25 Correct 47 ms 213332 KB Output is correct
26 Correct 45 ms 213072 KB Output is correct
27 Correct 46 ms 213260 KB Output is correct
28 Correct 51 ms 215084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 212624 KB Output is correct
2 Correct 45 ms 212568 KB Output is correct
3 Correct 46 ms 212572 KB Output is correct
4 Correct 46 ms 212652 KB Output is correct
5 Correct 50 ms 213080 KB Output is correct
6 Correct 45 ms 212828 KB Output is correct
7 Correct 45 ms 212568 KB Output is correct
8 Correct 46 ms 213084 KB Output is correct
9 Correct 54 ms 221776 KB Output is correct
10 Runtime error 193 ms 431188 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 212540 KB Output is correct
2 Correct 45 ms 212564 KB Output is correct
3 Correct 46 ms 212564 KB Output is correct
4 Correct 46 ms 212572 KB Output is correct
5 Correct 47 ms 212564 KB Output is correct
6 Correct 46 ms 212568 KB Output is correct
7 Correct 45 ms 212560 KB Output is correct
8 Correct 45 ms 212564 KB Output is correct
9 Correct 46 ms 212572 KB Output is correct
10 Correct 47 ms 212560 KB Output is correct
11 Correct 46 ms 212572 KB Output is correct
12 Correct 46 ms 212572 KB Output is correct
13 Correct 46 ms 212696 KB Output is correct
14 Correct 45 ms 212616 KB Output is correct
15 Correct 47 ms 212960 KB Output is correct
16 Correct 46 ms 212572 KB Output is correct
17 Correct 46 ms 212564 KB Output is correct
18 Correct 46 ms 212668 KB Output is correct
19 Correct 46 ms 212564 KB Output is correct
20 Correct 46 ms 212640 KB Output is correct
21 Correct 44 ms 212560 KB Output is correct
22 Correct 48 ms 212772 KB Output is correct
23 Correct 46 ms 212636 KB Output is correct
24 Correct 45 ms 212564 KB Output is correct
25 Correct 46 ms 212572 KB Output is correct
26 Correct 44 ms 212792 KB Output is correct
27 Correct 45 ms 212560 KB Output is correct
28 Correct 47 ms 212672 KB Output is correct
29 Correct 46 ms 212560 KB Output is correct
30 Correct 46 ms 212792 KB Output is correct
31 Correct 46 ms 212660 KB Output is correct
32 Correct 47 ms 212596 KB Output is correct
33 Correct 46 ms 212568 KB Output is correct
34 Correct 48 ms 212832 KB Output is correct
35 Correct 45 ms 212564 KB Output is correct
36 Correct 47 ms 212564 KB Output is correct
37 Correct 45 ms 212744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 212560 KB Output is correct
2 Correct 48 ms 212560 KB Output is correct
3 Correct 46 ms 212568 KB Output is correct
4 Correct 48 ms 212816 KB Output is correct
5 Correct 45 ms 212564 KB Output is correct
6 Correct 47 ms 212564 KB Output is correct
7 Correct 45 ms 212572 KB Output is correct
8 Correct 51 ms 213076 KB Output is correct
9 Correct 45 ms 212816 KB Output is correct
10 Correct 61 ms 221204 KB Output is correct
11 Correct 52 ms 216660 KB Output is correct
12 Correct 49 ms 213856 KB Output is correct
13 Correct 50 ms 214696 KB Output is correct
14 Correct 53 ms 216336 KB Output is correct
15 Correct 53 ms 216044 KB Output is correct
16 Correct 53 ms 216668 KB Output is correct
17 Correct 46 ms 212844 KB Output is correct
18 Correct 46 ms 213076 KB Output is correct
19 Correct 47 ms 212828 KB Output is correct
20 Correct 46 ms 212940 KB Output is correct
21 Correct 50 ms 214204 KB Output is correct
22 Correct 59 ms 217172 KB Output is correct
23 Correct 53 ms 216660 KB Output is correct
24 Correct 47 ms 213332 KB Output is correct
25 Correct 47 ms 213332 KB Output is correct
26 Correct 45 ms 213072 KB Output is correct
27 Correct 46 ms 213260 KB Output is correct
28 Correct 51 ms 215084 KB Output is correct
29 Correct 46 ms 212540 KB Output is correct
30 Correct 45 ms 212564 KB Output is correct
31 Correct 46 ms 212564 KB Output is correct
32 Correct 46 ms 212572 KB Output is correct
33 Correct 47 ms 212564 KB Output is correct
34 Correct 46 ms 212568 KB Output is correct
35 Correct 45 ms 212560 KB Output is correct
36 Correct 45 ms 212564 KB Output is correct
37 Correct 46 ms 212572 KB Output is correct
38 Correct 47 ms 212560 KB Output is correct
39 Correct 46 ms 212572 KB Output is correct
40 Correct 46 ms 212572 KB Output is correct
41 Correct 46 ms 212696 KB Output is correct
42 Correct 45 ms 212616 KB Output is correct
43 Correct 47 ms 212960 KB Output is correct
44 Correct 46 ms 212572 KB Output is correct
45 Correct 46 ms 212564 KB Output is correct
46 Correct 46 ms 212668 KB Output is correct
47 Correct 46 ms 212564 KB Output is correct
48 Correct 46 ms 212640 KB Output is correct
49 Correct 44 ms 212560 KB Output is correct
50 Correct 48 ms 212772 KB Output is correct
51 Correct 46 ms 212636 KB Output is correct
52 Correct 45 ms 212564 KB Output is correct
53 Correct 46 ms 212572 KB Output is correct
54 Correct 44 ms 212792 KB Output is correct
55 Correct 45 ms 212560 KB Output is correct
56 Correct 47 ms 212672 KB Output is correct
57 Correct 46 ms 212560 KB Output is correct
58 Correct 46 ms 212792 KB Output is correct
59 Correct 46 ms 212660 KB Output is correct
60 Correct 47 ms 212596 KB Output is correct
61 Correct 46 ms 212568 KB Output is correct
62 Correct 48 ms 212832 KB Output is correct
63 Correct 45 ms 212564 KB Output is correct
64 Correct 47 ms 212564 KB Output is correct
65 Correct 45 ms 212744 KB Output is correct
66 Correct 48 ms 212788 KB Output is correct
67 Correct 46 ms 213080 KB Output is correct
68 Correct 47 ms 212828 KB Output is correct
69 Correct 46 ms 212816 KB Output is correct
70 Correct 46 ms 213108 KB Output is correct
71 Correct 46 ms 213364 KB Output is correct
72 Correct 47 ms 213076 KB Output is correct
73 Correct 46 ms 212952 KB Output is correct
74 Correct 47 ms 212828 KB Output is correct
75 Correct 46 ms 213328 KB Output is correct
76 Correct 46 ms 213072 KB Output is correct
77 Correct 46 ms 213076 KB Output is correct
78 Correct 46 ms 213072 KB Output is correct
79 Correct 46 ms 213076 KB Output is correct
80 Correct 46 ms 213076 KB Output is correct
81 Correct 47 ms 212820 KB Output is correct
82 Correct 47 ms 213408 KB Output is correct
83 Correct 45 ms 212816 KB Output is correct
84 Correct 49 ms 213840 KB Output is correct
85 Correct 47 ms 213080 KB Output is correct
86 Correct 51 ms 213596 KB Output is correct
87 Correct 49 ms 213596 KB Output is correct
88 Correct 48 ms 213584 KB Output is correct
89 Correct 48 ms 213588 KB Output is correct
90 Correct 47 ms 213676 KB Output is correct
91 Correct 48 ms 213596 KB Output is correct
92 Correct 49 ms 214204 KB Output is correct
93 Correct 58 ms 219880 KB Output is correct
94 Correct 53 ms 216916 KB Output is correct
95 Correct 49 ms 213840 KB Output is correct
96 Correct 46 ms 213332 KB Output is correct
97 Correct 48 ms 213204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 212560 KB Output is correct
2 Correct 48 ms 212560 KB Output is correct
3 Correct 46 ms 212568 KB Output is correct
4 Correct 48 ms 212816 KB Output is correct
5 Correct 45 ms 212564 KB Output is correct
6 Correct 47 ms 212564 KB Output is correct
7 Correct 45 ms 212572 KB Output is correct
8 Correct 51 ms 213076 KB Output is correct
9 Correct 45 ms 212816 KB Output is correct
10 Correct 61 ms 221204 KB Output is correct
11 Correct 52 ms 216660 KB Output is correct
12 Correct 49 ms 213856 KB Output is correct
13 Correct 50 ms 214696 KB Output is correct
14 Correct 53 ms 216336 KB Output is correct
15 Correct 53 ms 216044 KB Output is correct
16 Correct 53 ms 216668 KB Output is correct
17 Correct 46 ms 212844 KB Output is correct
18 Correct 46 ms 213076 KB Output is correct
19 Correct 47 ms 212828 KB Output is correct
20 Correct 46 ms 212940 KB Output is correct
21 Correct 50 ms 214204 KB Output is correct
22 Correct 59 ms 217172 KB Output is correct
23 Correct 53 ms 216660 KB Output is correct
24 Correct 47 ms 213332 KB Output is correct
25 Correct 47 ms 213332 KB Output is correct
26 Correct 45 ms 213072 KB Output is correct
27 Correct 46 ms 213260 KB Output is correct
28 Correct 51 ms 215084 KB Output is correct
29 Correct 46 ms 212540 KB Output is correct
30 Correct 45 ms 212564 KB Output is correct
31 Correct 46 ms 212564 KB Output is correct
32 Correct 46 ms 212572 KB Output is correct
33 Correct 47 ms 212564 KB Output is correct
34 Correct 46 ms 212568 KB Output is correct
35 Correct 45 ms 212560 KB Output is correct
36 Correct 45 ms 212564 KB Output is correct
37 Correct 46 ms 212572 KB Output is correct
38 Correct 47 ms 212560 KB Output is correct
39 Correct 46 ms 212572 KB Output is correct
40 Correct 46 ms 212572 KB Output is correct
41 Correct 46 ms 212696 KB Output is correct
42 Correct 45 ms 212616 KB Output is correct
43 Correct 47 ms 212960 KB Output is correct
44 Correct 46 ms 212572 KB Output is correct
45 Correct 46 ms 212564 KB Output is correct
46 Correct 46 ms 212668 KB Output is correct
47 Correct 46 ms 212564 KB Output is correct
48 Correct 46 ms 212640 KB Output is correct
49 Correct 44 ms 212560 KB Output is correct
50 Correct 48 ms 212772 KB Output is correct
51 Correct 46 ms 212636 KB Output is correct
52 Correct 45 ms 212564 KB Output is correct
53 Correct 46 ms 212572 KB Output is correct
54 Correct 44 ms 212792 KB Output is correct
55 Correct 45 ms 212560 KB Output is correct
56 Correct 47 ms 212672 KB Output is correct
57 Correct 46 ms 212560 KB Output is correct
58 Correct 46 ms 212792 KB Output is correct
59 Correct 46 ms 212660 KB Output is correct
60 Correct 47 ms 212596 KB Output is correct
61 Correct 46 ms 212568 KB Output is correct
62 Correct 48 ms 212832 KB Output is correct
63 Correct 45 ms 212564 KB Output is correct
64 Correct 47 ms 212564 KB Output is correct
65 Correct 45 ms 212744 KB Output is correct
66 Correct 48 ms 212788 KB Output is correct
67 Correct 46 ms 213080 KB Output is correct
68 Correct 47 ms 212828 KB Output is correct
69 Correct 46 ms 212816 KB Output is correct
70 Correct 46 ms 213108 KB Output is correct
71 Correct 46 ms 213364 KB Output is correct
72 Correct 47 ms 213076 KB Output is correct
73 Correct 46 ms 212952 KB Output is correct
74 Correct 47 ms 212828 KB Output is correct
75 Correct 46 ms 213328 KB Output is correct
76 Correct 46 ms 213072 KB Output is correct
77 Correct 46 ms 213076 KB Output is correct
78 Correct 46 ms 213072 KB Output is correct
79 Correct 46 ms 213076 KB Output is correct
80 Correct 46 ms 213076 KB Output is correct
81 Correct 47 ms 212820 KB Output is correct
82 Correct 47 ms 213408 KB Output is correct
83 Correct 45 ms 212816 KB Output is correct
84 Correct 49 ms 213840 KB Output is correct
85 Correct 47 ms 213080 KB Output is correct
86 Correct 51 ms 213596 KB Output is correct
87 Correct 49 ms 213596 KB Output is correct
88 Correct 48 ms 213584 KB Output is correct
89 Correct 48 ms 213588 KB Output is correct
90 Correct 47 ms 213676 KB Output is correct
91 Correct 48 ms 213596 KB Output is correct
92 Correct 49 ms 214204 KB Output is correct
93 Correct 58 ms 219880 KB Output is correct
94 Correct 53 ms 216916 KB Output is correct
95 Correct 49 ms 213840 KB Output is correct
96 Correct 46 ms 213332 KB Output is correct
97 Correct 48 ms 213204 KB Output is correct
98 Correct 55 ms 221776 KB Output is correct
99 Correct 46 ms 212848 KB Output is correct
100 Correct 66 ms 226684 KB Output is correct
101 Correct 53 ms 217172 KB Output is correct
102 Correct 54 ms 217428 KB Output is correct
103 Correct 86 ms 240976 KB Output is correct
104 Correct 85 ms 238928 KB Output is correct
105 Correct 149 ms 276960 KB Output is correct
106 Correct 610 ms 489040 KB Output is correct
107 Correct 423 ms 375828 KB Output is correct
108 Correct 93 ms 247124 KB Output is correct
109 Correct 72 ms 230996 KB Output is correct
110 Correct 73 ms 231376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 212560 KB Output is correct
2 Correct 48 ms 212560 KB Output is correct
3 Correct 46 ms 212568 KB Output is correct
4 Correct 48 ms 212816 KB Output is correct
5 Correct 45 ms 212564 KB Output is correct
6 Correct 47 ms 212564 KB Output is correct
7 Correct 45 ms 212572 KB Output is correct
8 Correct 51 ms 213076 KB Output is correct
9 Correct 45 ms 212816 KB Output is correct
10 Correct 61 ms 221204 KB Output is correct
11 Correct 52 ms 216660 KB Output is correct
12 Correct 49 ms 213856 KB Output is correct
13 Correct 50 ms 214696 KB Output is correct
14 Correct 53 ms 216336 KB Output is correct
15 Correct 53 ms 216044 KB Output is correct
16 Correct 53 ms 216668 KB Output is correct
17 Correct 46 ms 212844 KB Output is correct
18 Correct 46 ms 213076 KB Output is correct
19 Correct 47 ms 212828 KB Output is correct
20 Correct 46 ms 212940 KB Output is correct
21 Correct 50 ms 214204 KB Output is correct
22 Correct 59 ms 217172 KB Output is correct
23 Correct 53 ms 216660 KB Output is correct
24 Correct 47 ms 213332 KB Output is correct
25 Correct 47 ms 213332 KB Output is correct
26 Correct 45 ms 213072 KB Output is correct
27 Correct 46 ms 213260 KB Output is correct
28 Correct 51 ms 215084 KB Output is correct
29 Correct 47 ms 212624 KB Output is correct
30 Correct 45 ms 212568 KB Output is correct
31 Correct 46 ms 212572 KB Output is correct
32 Correct 46 ms 212652 KB Output is correct
33 Correct 50 ms 213080 KB Output is correct
34 Correct 45 ms 212828 KB Output is correct
35 Correct 45 ms 212568 KB Output is correct
36 Correct 46 ms 213084 KB Output is correct
37 Correct 54 ms 221776 KB Output is correct
38 Runtime error 193 ms 431188 KB Execution killed with signal 11
39 Halted 0 ms 0 KB -