답안 #891996

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
891996 2023-12-24T15:20:50 Z alexander707070 Cookies (JOI23_cookies) C++14
63 / 100
151 ms 55472 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;
unordered_map<int,int> dp[MAXN][MAXN];

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

    if(dp[box][sum][pos]!=0)return dp[box][sum][pos];

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

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

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

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:85:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     for(int i=0;i<w.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14428 KB Output is correct
2 Correct 4 ms 14428 KB Output is correct
3 Correct 4 ms 14424 KB Output is correct
4 Correct 4 ms 14532 KB Output is correct
5 Correct 4 ms 14592 KB Output is correct
6 Correct 4 ms 14452 KB Output is correct
7 Correct 4 ms 14424 KB Output is correct
8 Correct 8 ms 14664 KB Output is correct
9 Correct 5 ms 14532 KB Output is correct
10 Correct 151 ms 55472 KB Output is correct
11 Correct 15 ms 18780 KB Output is correct
12 Correct 54 ms 28520 KB Output is correct
13 Correct 9 ms 15964 KB Output is correct
14 Correct 15 ms 18780 KB Output is correct
15 Correct 14 ms 18280 KB Output is correct
16 Correct 15 ms 19288 KB Output is correct
17 Correct 5 ms 14684 KB Output is correct
18 Correct 13 ms 17756 KB Output is correct
19 Correct 5 ms 14684 KB Output is correct
20 Correct 4 ms 14428 KB Output is correct
21 Correct 15 ms 18268 KB Output is correct
22 Correct 32 ms 23860 KB Output is correct
23 Correct 29 ms 22620 KB Output is correct
24 Correct 10 ms 16480 KB Output is correct
25 Correct 9 ms 16472 KB Output is correct
26 Correct 5 ms 14680 KB Output is correct
27 Correct 5 ms 14936 KB Output is correct
28 Correct 9 ms 16220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14680 KB Output is correct
2 Correct 4 ms 14428 KB Output is correct
3 Correct 4 ms 14424 KB Output is correct
4 Correct 4 ms 14428 KB Output is correct
5 Correct 8 ms 14428 KB Output is correct
6 Correct 4 ms 14428 KB Output is correct
7 Correct 4 ms 14428 KB Output is correct
8 Correct 5 ms 14428 KB Output is correct
9 Runtime error 13 ms 29020 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14428 KB Output is correct
2 Correct 4 ms 14528 KB Output is correct
3 Correct 4 ms 14428 KB Output is correct
4 Correct 4 ms 14428 KB Output is correct
5 Correct 4 ms 14460 KB Output is correct
6 Correct 4 ms 14428 KB Output is correct
7 Correct 4 ms 14428 KB Output is correct
8 Correct 4 ms 14444 KB Output is correct
9 Correct 4 ms 14428 KB Output is correct
10 Correct 4 ms 14428 KB Output is correct
11 Correct 4 ms 14444 KB Output is correct
12 Correct 4 ms 14440 KB Output is correct
13 Correct 4 ms 14428 KB Output is correct
14 Correct 4 ms 14428 KB Output is correct
15 Correct 4 ms 14424 KB Output is correct
16 Correct 4 ms 14428 KB Output is correct
17 Correct 4 ms 14428 KB Output is correct
18 Correct 4 ms 14428 KB Output is correct
19 Correct 4 ms 14428 KB Output is correct
20 Correct 4 ms 14448 KB Output is correct
21 Correct 4 ms 14428 KB Output is correct
22 Correct 4 ms 14428 KB Output is correct
23 Correct 4 ms 14428 KB Output is correct
24 Correct 4 ms 14428 KB Output is correct
25 Correct 4 ms 14424 KB Output is correct
26 Correct 4 ms 14428 KB Output is correct
27 Correct 4 ms 14428 KB Output is correct
28 Correct 4 ms 14428 KB Output is correct
29 Correct 4 ms 14540 KB Output is correct
30 Correct 4 ms 14428 KB Output is correct
31 Correct 4 ms 14428 KB Output is correct
32 Correct 4 ms 14424 KB Output is correct
33 Correct 4 ms 14428 KB Output is correct
34 Correct 4 ms 14428 KB Output is correct
35 Correct 4 ms 14428 KB Output is correct
36 Correct 4 ms 14448 KB Output is correct
37 Correct 4 ms 14428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14428 KB Output is correct
2 Correct 4 ms 14428 KB Output is correct
3 Correct 4 ms 14424 KB Output is correct
4 Correct 4 ms 14532 KB Output is correct
5 Correct 4 ms 14592 KB Output is correct
6 Correct 4 ms 14452 KB Output is correct
7 Correct 4 ms 14424 KB Output is correct
8 Correct 8 ms 14664 KB Output is correct
9 Correct 5 ms 14532 KB Output is correct
10 Correct 151 ms 55472 KB Output is correct
11 Correct 15 ms 18780 KB Output is correct
12 Correct 54 ms 28520 KB Output is correct
13 Correct 9 ms 15964 KB Output is correct
14 Correct 15 ms 18780 KB Output is correct
15 Correct 14 ms 18280 KB Output is correct
16 Correct 15 ms 19288 KB Output is correct
17 Correct 5 ms 14684 KB Output is correct
18 Correct 13 ms 17756 KB Output is correct
19 Correct 5 ms 14684 KB Output is correct
20 Correct 4 ms 14428 KB Output is correct
21 Correct 15 ms 18268 KB Output is correct
22 Correct 32 ms 23860 KB Output is correct
23 Correct 29 ms 22620 KB Output is correct
24 Correct 10 ms 16480 KB Output is correct
25 Correct 9 ms 16472 KB Output is correct
26 Correct 5 ms 14680 KB Output is correct
27 Correct 5 ms 14936 KB Output is correct
28 Correct 9 ms 16220 KB Output is correct
29 Correct 4 ms 14428 KB Output is correct
30 Correct 4 ms 14528 KB Output is correct
31 Correct 4 ms 14428 KB Output is correct
32 Correct 4 ms 14428 KB Output is correct
33 Correct 4 ms 14460 KB Output is correct
34 Correct 4 ms 14428 KB Output is correct
35 Correct 4 ms 14428 KB Output is correct
36 Correct 4 ms 14444 KB Output is correct
37 Correct 4 ms 14428 KB Output is correct
38 Correct 4 ms 14428 KB Output is correct
39 Correct 4 ms 14444 KB Output is correct
40 Correct 4 ms 14440 KB Output is correct
41 Correct 4 ms 14428 KB Output is correct
42 Correct 4 ms 14428 KB Output is correct
43 Correct 4 ms 14424 KB Output is correct
44 Correct 4 ms 14428 KB Output is correct
45 Correct 4 ms 14428 KB Output is correct
46 Correct 4 ms 14428 KB Output is correct
47 Correct 4 ms 14428 KB Output is correct
48 Correct 4 ms 14448 KB Output is correct
49 Correct 4 ms 14428 KB Output is correct
50 Correct 4 ms 14428 KB Output is correct
51 Correct 4 ms 14428 KB Output is correct
52 Correct 4 ms 14428 KB Output is correct
53 Correct 4 ms 14424 KB Output is correct
54 Correct 4 ms 14428 KB Output is correct
55 Correct 4 ms 14428 KB Output is correct
56 Correct 4 ms 14428 KB Output is correct
57 Correct 4 ms 14540 KB Output is correct
58 Correct 4 ms 14428 KB Output is correct
59 Correct 4 ms 14428 KB Output is correct
60 Correct 4 ms 14424 KB Output is correct
61 Correct 4 ms 14428 KB Output is correct
62 Correct 4 ms 14428 KB Output is correct
63 Correct 4 ms 14428 KB Output is correct
64 Correct 4 ms 14448 KB Output is correct
65 Correct 4 ms 14428 KB Output is correct
66 Correct 4 ms 14680 KB Output is correct
67 Correct 5 ms 14428 KB Output is correct
68 Correct 4 ms 14460 KB Output is correct
69 Correct 4 ms 14428 KB Output is correct
70 Correct 5 ms 14940 KB Output is correct
71 Correct 23 ms 21800 KB Output is correct
72 Correct 7 ms 15964 KB Output is correct
73 Correct 6 ms 14684 KB Output is correct
74 Correct 5 ms 14940 KB Output is correct
75 Correct 18 ms 20060 KB Output is correct
76 Correct 23 ms 20060 KB Output is correct
77 Correct 24 ms 22000 KB Output is correct
78 Correct 16 ms 19292 KB Output is correct
79 Correct 18 ms 19968 KB Output is correct
80 Correct 18 ms 20220 KB Output is correct
81 Correct 6 ms 15196 KB Output is correct
82 Correct 29 ms 23384 KB Output is correct
83 Correct 4 ms 14684 KB Output is correct
84 Correct 36 ms 25432 KB Output is correct
85 Correct 23 ms 20944 KB Output is correct
86 Correct 54 ms 29404 KB Output is correct
87 Correct 48 ms 28172 KB Output is correct
88 Correct 51 ms 28500 KB Output is correct
89 Correct 60 ms 30680 KB Output is correct
90 Correct 46 ms 27812 KB Output is correct
91 Correct 45 ms 27992 KB Output is correct
92 Correct 62 ms 30876 KB Output is correct
93 Correct 74 ms 35668 KB Output is correct
94 Correct 42 ms 26196 KB Output is correct
95 Correct 40 ms 26452 KB Output is correct
96 Correct 22 ms 21336 KB Output is correct
97 Correct 22 ms 21336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14428 KB Output is correct
2 Correct 4 ms 14428 KB Output is correct
3 Correct 4 ms 14424 KB Output is correct
4 Correct 4 ms 14532 KB Output is correct
5 Correct 4 ms 14592 KB Output is correct
6 Correct 4 ms 14452 KB Output is correct
7 Correct 4 ms 14424 KB Output is correct
8 Correct 8 ms 14664 KB Output is correct
9 Correct 5 ms 14532 KB Output is correct
10 Correct 151 ms 55472 KB Output is correct
11 Correct 15 ms 18780 KB Output is correct
12 Correct 54 ms 28520 KB Output is correct
13 Correct 9 ms 15964 KB Output is correct
14 Correct 15 ms 18780 KB Output is correct
15 Correct 14 ms 18280 KB Output is correct
16 Correct 15 ms 19288 KB Output is correct
17 Correct 5 ms 14684 KB Output is correct
18 Correct 13 ms 17756 KB Output is correct
19 Correct 5 ms 14684 KB Output is correct
20 Correct 4 ms 14428 KB Output is correct
21 Correct 15 ms 18268 KB Output is correct
22 Correct 32 ms 23860 KB Output is correct
23 Correct 29 ms 22620 KB Output is correct
24 Correct 10 ms 16480 KB Output is correct
25 Correct 9 ms 16472 KB Output is correct
26 Correct 5 ms 14680 KB Output is correct
27 Correct 5 ms 14936 KB Output is correct
28 Correct 9 ms 16220 KB Output is correct
29 Correct 4 ms 14428 KB Output is correct
30 Correct 4 ms 14528 KB Output is correct
31 Correct 4 ms 14428 KB Output is correct
32 Correct 4 ms 14428 KB Output is correct
33 Correct 4 ms 14460 KB Output is correct
34 Correct 4 ms 14428 KB Output is correct
35 Correct 4 ms 14428 KB Output is correct
36 Correct 4 ms 14444 KB Output is correct
37 Correct 4 ms 14428 KB Output is correct
38 Correct 4 ms 14428 KB Output is correct
39 Correct 4 ms 14444 KB Output is correct
40 Correct 4 ms 14440 KB Output is correct
41 Correct 4 ms 14428 KB Output is correct
42 Correct 4 ms 14428 KB Output is correct
43 Correct 4 ms 14424 KB Output is correct
44 Correct 4 ms 14428 KB Output is correct
45 Correct 4 ms 14428 KB Output is correct
46 Correct 4 ms 14428 KB Output is correct
47 Correct 4 ms 14428 KB Output is correct
48 Correct 4 ms 14448 KB Output is correct
49 Correct 4 ms 14428 KB Output is correct
50 Correct 4 ms 14428 KB Output is correct
51 Correct 4 ms 14428 KB Output is correct
52 Correct 4 ms 14428 KB Output is correct
53 Correct 4 ms 14424 KB Output is correct
54 Correct 4 ms 14428 KB Output is correct
55 Correct 4 ms 14428 KB Output is correct
56 Correct 4 ms 14428 KB Output is correct
57 Correct 4 ms 14540 KB Output is correct
58 Correct 4 ms 14428 KB Output is correct
59 Correct 4 ms 14428 KB Output is correct
60 Correct 4 ms 14424 KB Output is correct
61 Correct 4 ms 14428 KB Output is correct
62 Correct 4 ms 14428 KB Output is correct
63 Correct 4 ms 14428 KB Output is correct
64 Correct 4 ms 14448 KB Output is correct
65 Correct 4 ms 14428 KB Output is correct
66 Correct 4 ms 14680 KB Output is correct
67 Correct 5 ms 14428 KB Output is correct
68 Correct 4 ms 14460 KB Output is correct
69 Correct 4 ms 14428 KB Output is correct
70 Correct 5 ms 14940 KB Output is correct
71 Correct 23 ms 21800 KB Output is correct
72 Correct 7 ms 15964 KB Output is correct
73 Correct 6 ms 14684 KB Output is correct
74 Correct 5 ms 14940 KB Output is correct
75 Correct 18 ms 20060 KB Output is correct
76 Correct 23 ms 20060 KB Output is correct
77 Correct 24 ms 22000 KB Output is correct
78 Correct 16 ms 19292 KB Output is correct
79 Correct 18 ms 19968 KB Output is correct
80 Correct 18 ms 20220 KB Output is correct
81 Correct 6 ms 15196 KB Output is correct
82 Correct 29 ms 23384 KB Output is correct
83 Correct 4 ms 14684 KB Output is correct
84 Correct 36 ms 25432 KB Output is correct
85 Correct 23 ms 20944 KB Output is correct
86 Correct 54 ms 29404 KB Output is correct
87 Correct 48 ms 28172 KB Output is correct
88 Correct 51 ms 28500 KB Output is correct
89 Correct 60 ms 30680 KB Output is correct
90 Correct 46 ms 27812 KB Output is correct
91 Correct 45 ms 27992 KB Output is correct
92 Correct 62 ms 30876 KB Output is correct
93 Correct 74 ms 35668 KB Output is correct
94 Correct 42 ms 26196 KB Output is correct
95 Correct 40 ms 26452 KB Output is correct
96 Correct 22 ms 21336 KB Output is correct
97 Correct 22 ms 21336 KB Output is correct
98 Runtime error 13 ms 29016 KB Execution killed with signal 11
99 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14428 KB Output is correct
2 Correct 4 ms 14428 KB Output is correct
3 Correct 4 ms 14424 KB Output is correct
4 Correct 4 ms 14532 KB Output is correct
5 Correct 4 ms 14592 KB Output is correct
6 Correct 4 ms 14452 KB Output is correct
7 Correct 4 ms 14424 KB Output is correct
8 Correct 8 ms 14664 KB Output is correct
9 Correct 5 ms 14532 KB Output is correct
10 Correct 151 ms 55472 KB Output is correct
11 Correct 15 ms 18780 KB Output is correct
12 Correct 54 ms 28520 KB Output is correct
13 Correct 9 ms 15964 KB Output is correct
14 Correct 15 ms 18780 KB Output is correct
15 Correct 14 ms 18280 KB Output is correct
16 Correct 15 ms 19288 KB Output is correct
17 Correct 5 ms 14684 KB Output is correct
18 Correct 13 ms 17756 KB Output is correct
19 Correct 5 ms 14684 KB Output is correct
20 Correct 4 ms 14428 KB Output is correct
21 Correct 15 ms 18268 KB Output is correct
22 Correct 32 ms 23860 KB Output is correct
23 Correct 29 ms 22620 KB Output is correct
24 Correct 10 ms 16480 KB Output is correct
25 Correct 9 ms 16472 KB Output is correct
26 Correct 5 ms 14680 KB Output is correct
27 Correct 5 ms 14936 KB Output is correct
28 Correct 9 ms 16220 KB Output is correct
29 Correct 4 ms 14680 KB Output is correct
30 Correct 4 ms 14428 KB Output is correct
31 Correct 4 ms 14424 KB Output is correct
32 Correct 4 ms 14428 KB Output is correct
33 Correct 8 ms 14428 KB Output is correct
34 Correct 4 ms 14428 KB Output is correct
35 Correct 4 ms 14428 KB Output is correct
36 Correct 5 ms 14428 KB Output is correct
37 Runtime error 13 ms 29020 KB Execution killed with signal 11
38 Halted 0 ms 0 KB -