Submission #891995

# Submission time Handle Problem Language Result Execution time Memory
891995 2023-12-24T15:13:12 Z alexander707070 Cookies (JOI23_cookies) C++14
63 / 100
49 ms 399752 KB
#include<bits/stdc++.h>
#define MAXN 507
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;
bool li[MAXN][MAXN][MAXN];
int dp[MAXN][MAXN][MAXN];

int ff(int pos,int box,int sum){
    if(sum<0 or box<1)return 1000000;
    if(sum==0)return 0;

    if(li[pos][box][sum])return dp[pos][box][sum];
    li[pos][box][sum]=true;

    dp[pos][box][sum]=ff(pos,box-1,sum);

    if(total-sum+b[box]<=maxs[pos]){
        dp[pos][box][sum]=min(dp[pos][box][sum],ff(pos+1,box,sum-b[box])+1);
    }

    return dp[pos][box][sum];
}

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

    if(ff(pos,box,sum)==ff(pos,box-1,sum)){
        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(){

    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];
    }

    if(ff(1,m,total)>total){
        cout<<"-1\n";
        return 0;
    }

    solve(1,m,total);
    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:87:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |     for(int i=0;i<w.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2512 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 8648 KB Output is correct
8 Correct 43 ms 389060 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 49 ms 394800 KB Output is correct
11 Correct 1 ms 4696 KB Output is correct
12 Correct 30 ms 254568 KB Output is correct
13 Correct 27 ms 254044 KB Output is correct
14 Correct 4 ms 23388 KB Output is correct
15 Correct 7 ms 56248 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 11 ms 101468 KB Output is correct
18 Correct 26 ms 254036 KB Output is correct
19 Correct 4 ms 29276 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 6 ms 47960 KB Output is correct
22 Correct 28 ms 254556 KB Output is correct
23 Correct 15 ms 128860 KB Output is correct
24 Correct 41 ms 397396 KB Output is correct
25 Correct 41 ms 399364 KB Output is correct
26 Correct 4 ms 33368 KB Output is correct
27 Correct 4 ms 33372 KB Output is correct
28 Correct 5 ms 33628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 43 ms 389176 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 2 ms 16732 KB Output is correct
8 Correct 39 ms 389044 KB Output is correct
9 Runtime error 12 ms 348 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 2 ms 16732 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 2 ms 16732 KB Output is correct
16 Correct 1 ms 8536 KB Output is correct
17 Correct 2 ms 16732 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 3 ms 16988 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 2 ms 16948 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 2 ms 16732 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 2 ms 16732 KB Output is correct
30 Correct 2 ms 16732 KB Output is correct
31 Correct 2 ms 16732 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 2 ms 16732 KB Output is correct
34 Correct 1 ms 6488 KB Output is correct
35 Correct 2 ms 16732 KB Output is correct
36 Correct 2 ms 16732 KB Output is correct
37 Correct 1 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2512 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 8648 KB Output is correct
8 Correct 43 ms 389060 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 49 ms 394800 KB Output is correct
11 Correct 1 ms 4696 KB Output is correct
12 Correct 30 ms 254568 KB Output is correct
13 Correct 27 ms 254044 KB Output is correct
14 Correct 4 ms 23388 KB Output is correct
15 Correct 7 ms 56248 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 11 ms 101468 KB Output is correct
18 Correct 26 ms 254036 KB Output is correct
19 Correct 4 ms 29276 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 6 ms 47960 KB Output is correct
22 Correct 28 ms 254556 KB Output is correct
23 Correct 15 ms 128860 KB Output is correct
24 Correct 41 ms 397396 KB Output is correct
25 Correct 41 ms 399364 KB Output is correct
26 Correct 4 ms 33368 KB Output is correct
27 Correct 4 ms 33372 KB Output is correct
28 Correct 5 ms 33628 KB Output is correct
29 Correct 1 ms 8540 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 8540 KB Output is correct
37 Correct 2 ms 16732 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 0 ms 2396 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 2 ms 16732 KB Output is correct
44 Correct 1 ms 8536 KB Output is correct
45 Correct 2 ms 16732 KB Output is correct
46 Correct 1 ms 6492 KB Output is correct
47 Correct 3 ms 16988 KB Output is correct
48 Correct 1 ms 8540 KB Output is correct
49 Correct 1 ms 8540 KB Output is correct
50 Correct 1 ms 6492 KB Output is correct
51 Correct 1 ms 8540 KB Output is correct
52 Correct 2 ms 16948 KB Output is correct
53 Correct 1 ms 8540 KB Output is correct
54 Correct 1 ms 8540 KB Output is correct
55 Correct 2 ms 16732 KB Output is correct
56 Correct 1 ms 8540 KB Output is correct
57 Correct 2 ms 16732 KB Output is correct
58 Correct 2 ms 16732 KB Output is correct
59 Correct 2 ms 16732 KB Output is correct
60 Correct 1 ms 4444 KB Output is correct
61 Correct 2 ms 16732 KB Output is correct
62 Correct 1 ms 6488 KB Output is correct
63 Correct 2 ms 16732 KB Output is correct
64 Correct 2 ms 16732 KB Output is correct
65 Correct 1 ms 8540 KB Output is correct
66 Correct 2 ms 10588 KB Output is correct
67 Correct 39 ms 397316 KB Output is correct
68 Correct 6 ms 51804 KB Output is correct
69 Correct 6 ms 51920 KB Output is correct
70 Correct 4 ms 29276 KB Output is correct
71 Correct 42 ms 397524 KB Output is correct
72 Correct 40 ms 397412 KB Output is correct
73 Correct 3 ms 25180 KB Output is correct
74 Correct 10 ms 86976 KB Output is correct
75 Correct 42 ms 397452 KB Output is correct
76 Correct 43 ms 399472 KB Output is correct
77 Correct 41 ms 397392 KB Output is correct
78 Correct 43 ms 399444 KB Output is correct
79 Correct 41 ms 396880 KB Output is correct
80 Correct 43 ms 395512 KB Output is correct
81 Correct 7 ms 64348 KB Output is correct
82 Correct 43 ms 399752 KB Output is correct
83 Correct 3 ms 21080 KB Output is correct
84 Correct 42 ms 397652 KB Output is correct
85 Correct 27 ms 254036 KB Output is correct
86 Correct 45 ms 397908 KB Output is correct
87 Correct 45 ms 397684 KB Output is correct
88 Correct 48 ms 399736 KB Output is correct
89 Correct 45 ms 397908 KB Output is correct
90 Correct 44 ms 399700 KB Output is correct
91 Correct 43 ms 397620 KB Output is correct
92 Correct 44 ms 397988 KB Output is correct
93 Correct 11 ms 58968 KB Output is correct
94 Correct 44 ms 398164 KB Output is correct
95 Correct 43 ms 397644 KB Output is correct
96 Correct 42 ms 397648 KB Output is correct
97 Correct 42 ms 399700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2512 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 8648 KB Output is correct
8 Correct 43 ms 389060 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 49 ms 394800 KB Output is correct
11 Correct 1 ms 4696 KB Output is correct
12 Correct 30 ms 254568 KB Output is correct
13 Correct 27 ms 254044 KB Output is correct
14 Correct 4 ms 23388 KB Output is correct
15 Correct 7 ms 56248 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 11 ms 101468 KB Output is correct
18 Correct 26 ms 254036 KB Output is correct
19 Correct 4 ms 29276 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 6 ms 47960 KB Output is correct
22 Correct 28 ms 254556 KB Output is correct
23 Correct 15 ms 128860 KB Output is correct
24 Correct 41 ms 397396 KB Output is correct
25 Correct 41 ms 399364 KB Output is correct
26 Correct 4 ms 33368 KB Output is correct
27 Correct 4 ms 33372 KB Output is correct
28 Correct 5 ms 33628 KB Output is correct
29 Correct 1 ms 8540 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 8540 KB Output is correct
37 Correct 2 ms 16732 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 0 ms 2396 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 2 ms 16732 KB Output is correct
44 Correct 1 ms 8536 KB Output is correct
45 Correct 2 ms 16732 KB Output is correct
46 Correct 1 ms 6492 KB Output is correct
47 Correct 3 ms 16988 KB Output is correct
48 Correct 1 ms 8540 KB Output is correct
49 Correct 1 ms 8540 KB Output is correct
50 Correct 1 ms 6492 KB Output is correct
51 Correct 1 ms 8540 KB Output is correct
52 Correct 2 ms 16948 KB Output is correct
53 Correct 1 ms 8540 KB Output is correct
54 Correct 1 ms 8540 KB Output is correct
55 Correct 2 ms 16732 KB Output is correct
56 Correct 1 ms 8540 KB Output is correct
57 Correct 2 ms 16732 KB Output is correct
58 Correct 2 ms 16732 KB Output is correct
59 Correct 2 ms 16732 KB Output is correct
60 Correct 1 ms 4444 KB Output is correct
61 Correct 2 ms 16732 KB Output is correct
62 Correct 1 ms 6488 KB Output is correct
63 Correct 2 ms 16732 KB Output is correct
64 Correct 2 ms 16732 KB Output is correct
65 Correct 1 ms 8540 KB Output is correct
66 Correct 2 ms 10588 KB Output is correct
67 Correct 39 ms 397316 KB Output is correct
68 Correct 6 ms 51804 KB Output is correct
69 Correct 6 ms 51920 KB Output is correct
70 Correct 4 ms 29276 KB Output is correct
71 Correct 42 ms 397524 KB Output is correct
72 Correct 40 ms 397412 KB Output is correct
73 Correct 3 ms 25180 KB Output is correct
74 Correct 10 ms 86976 KB Output is correct
75 Correct 42 ms 397452 KB Output is correct
76 Correct 43 ms 399472 KB Output is correct
77 Correct 41 ms 397392 KB Output is correct
78 Correct 43 ms 399444 KB Output is correct
79 Correct 41 ms 396880 KB Output is correct
80 Correct 43 ms 395512 KB Output is correct
81 Correct 7 ms 64348 KB Output is correct
82 Correct 43 ms 399752 KB Output is correct
83 Correct 3 ms 21080 KB Output is correct
84 Correct 42 ms 397652 KB Output is correct
85 Correct 27 ms 254036 KB Output is correct
86 Correct 45 ms 397908 KB Output is correct
87 Correct 45 ms 397684 KB Output is correct
88 Correct 48 ms 399736 KB Output is correct
89 Correct 45 ms 397908 KB Output is correct
90 Correct 44 ms 399700 KB Output is correct
91 Correct 43 ms 397620 KB Output is correct
92 Correct 44 ms 397988 KB Output is correct
93 Correct 11 ms 58968 KB Output is correct
94 Correct 44 ms 398164 KB Output is correct
95 Correct 43 ms 397644 KB Output is correct
96 Correct 42 ms 397648 KB Output is correct
97 Correct 42 ms 399700 KB Output is correct
98 Runtime error 15 ms 348 KB Execution killed with signal 11
99 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2512 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 8648 KB Output is correct
8 Correct 43 ms 389060 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 49 ms 394800 KB Output is correct
11 Correct 1 ms 4696 KB Output is correct
12 Correct 30 ms 254568 KB Output is correct
13 Correct 27 ms 254044 KB Output is correct
14 Correct 4 ms 23388 KB Output is correct
15 Correct 7 ms 56248 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 11 ms 101468 KB Output is correct
18 Correct 26 ms 254036 KB Output is correct
19 Correct 4 ms 29276 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 6 ms 47960 KB Output is correct
22 Correct 28 ms 254556 KB Output is correct
23 Correct 15 ms 128860 KB Output is correct
24 Correct 41 ms 397396 KB Output is correct
25 Correct 41 ms 399364 KB Output is correct
26 Correct 4 ms 33368 KB Output is correct
27 Correct 4 ms 33372 KB Output is correct
28 Correct 5 ms 33628 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 43 ms 389176 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 2 ms 16732 KB Output is correct
36 Correct 39 ms 389044 KB Output is correct
37 Runtime error 12 ms 348 KB Execution killed with signal 11
38 Halted 0 ms 0 KB -