Submission #891993

# Submission time Handle Problem Language Result Execution time Memory
891993 2023-12-24T15:11:05 Z alexander707070 Cookies (JOI23_cookies) C++14
6 / 100
49 ms 403540 KB
#include<bits/stdc++.h>
#define MAXN 507
using namespace std;

int n,m,pt,total;
int a[MAXN],b[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]);
}

int main(){

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        total+=a[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(a+1,a+n+1);
    reverse(a+1,a+n+1);

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

        for(int f=0;f<a[i];f++){
            v[f].first--;
            w[v[f].second-1].push_back(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:83:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     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 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 43 ms 385000 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 49 ms 388616 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 30 ms 254696 KB Output is correct
13 Correct 28 ms 254036 KB Output is correct
14 Correct 4 ms 23388 KB Output is correct
15 Correct 7 ms 56252 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 254032 KB Output is correct
19 Correct 4 ms 29276 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 7 ms 47964 KB Output is correct
22 Correct 28 ms 254544 KB Output is correct
23 Correct 15 ms 128688 KB Output is correct
24 Correct 40 ms 403540 KB Output is correct
25 Correct 42 ms 401452 KB Output is correct
26 Correct 4 ms 33372 KB Output is correct
27 Correct 4 ms 33372 KB Output is correct
28 Correct 4 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 1 ms 2396 KB Output is correct
5 Correct 44 ms 397184 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 2 ms 16728 KB Output is correct
8 Correct 40 ms 403292 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 8536 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 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 4440 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Incorrect 1 ms 4444 KB Number of cookies does not match with A_i
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 43 ms 385000 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 49 ms 388616 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 30 ms 254696 KB Output is correct
13 Correct 28 ms 254036 KB Output is correct
14 Correct 4 ms 23388 KB Output is correct
15 Correct 7 ms 56252 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 254032 KB Output is correct
19 Correct 4 ms 29276 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 7 ms 47964 KB Output is correct
22 Correct 28 ms 254544 KB Output is correct
23 Correct 15 ms 128688 KB Output is correct
24 Correct 40 ms 403540 KB Output is correct
25 Correct 42 ms 401452 KB Output is correct
26 Correct 4 ms 33372 KB Output is correct
27 Correct 4 ms 33372 KB Output is correct
28 Correct 4 ms 33628 KB Output is correct
29 Correct 1 ms 8536 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2392 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 0 ms 2396 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 4440 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Incorrect 1 ms 4444 KB Number of cookies does not match with A_i
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 43 ms 385000 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 49 ms 388616 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 30 ms 254696 KB Output is correct
13 Correct 28 ms 254036 KB Output is correct
14 Correct 4 ms 23388 KB Output is correct
15 Correct 7 ms 56252 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 254032 KB Output is correct
19 Correct 4 ms 29276 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 7 ms 47964 KB Output is correct
22 Correct 28 ms 254544 KB Output is correct
23 Correct 15 ms 128688 KB Output is correct
24 Correct 40 ms 403540 KB Output is correct
25 Correct 42 ms 401452 KB Output is correct
26 Correct 4 ms 33372 KB Output is correct
27 Correct 4 ms 33372 KB Output is correct
28 Correct 4 ms 33628 KB Output is correct
29 Correct 1 ms 8536 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2392 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 0 ms 2396 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 4440 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Incorrect 1 ms 4444 KB Number of cookies does not match with A_i
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 43 ms 385000 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 49 ms 388616 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 30 ms 254696 KB Output is correct
13 Correct 28 ms 254036 KB Output is correct
14 Correct 4 ms 23388 KB Output is correct
15 Correct 7 ms 56252 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 254032 KB Output is correct
19 Correct 4 ms 29276 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 7 ms 47964 KB Output is correct
22 Correct 28 ms 254544 KB Output is correct
23 Correct 15 ms 128688 KB Output is correct
24 Correct 40 ms 403540 KB Output is correct
25 Correct 42 ms 401452 KB Output is correct
26 Correct 4 ms 33372 KB Output is correct
27 Correct 4 ms 33372 KB Output is correct
28 Correct 4 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 1 ms 2396 KB Output is correct
33 Correct 44 ms 397184 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 2 ms 16728 KB Output is correct
36 Correct 40 ms 403292 KB Output is correct
37 Runtime error 12 ms 348 KB Execution killed with signal 11
38 Halted 0 ms 0 KB -