답안 #892021

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
892021 2023-12-24T16:13:38 Z alexander707070 Cookies (JOI23_cookies) C++14
63 / 100
1000 ms 1005120 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;
unordered_map<short,short> dp[MAXN][MAXN];

void calc_dp(){
    for(int pos=total;pos>=1;pos--){
        for(int box=1;box<=m;box++){
            for(int sum=max(0,total-(pos-1)*b[m]);sum<=total-(pos-1)*b[box];sum++){

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

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

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

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

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

    if(box>1 and dp[box][sum][pos]==dp[box-1][sum][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[m][total][1]>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:100:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |     for(int i=0;i<w.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 495908 KB Output is correct
2 Correct 115 ms 496112 KB Output is correct
3 Correct 120 ms 495872 KB Output is correct
4 Correct 116 ms 495700 KB Output is correct
5 Correct 115 ms 495904 KB Output is correct
6 Correct 117 ms 495696 KB Output is correct
7 Correct 116 ms 495788 KB Output is correct
8 Correct 119 ms 496024 KB Output is correct
9 Correct 115 ms 495924 KB Output is correct
10 Correct 220 ms 537172 KB Output is correct
11 Correct 126 ms 500196 KB Output is correct
12 Correct 156 ms 509776 KB Output is correct
13 Correct 129 ms 500620 KB Output is correct
14 Correct 131 ms 501980 KB Output is correct
15 Correct 128 ms 501652 KB Output is correct
16 Correct 127 ms 501912 KB Output is correct
17 Correct 118 ms 496644 KB Output is correct
18 Correct 128 ms 499540 KB Output is correct
19 Correct 117 ms 496468 KB Output is correct
20 Correct 117 ms 496216 KB Output is correct
21 Correct 130 ms 501584 KB Output is correct
22 Correct 163 ms 514516 KB Output is correct
23 Correct 154 ms 511824 KB Output is correct
24 Correct 140 ms 502612 KB Output is correct
25 Correct 134 ms 502356 KB Output is correct
26 Correct 120 ms 497488 KB Output is correct
27 Correct 118 ms 497236 KB Output is correct
28 Correct 125 ms 499028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 496084 KB Output is correct
2 Correct 117 ms 495700 KB Output is correct
3 Correct 117 ms 495896 KB Output is correct
4 Correct 117 ms 495828 KB Output is correct
5 Correct 121 ms 495936 KB Output is correct
6 Correct 116 ms 495884 KB Output is correct
7 Correct 126 ms 495728 KB Output is correct
8 Correct 117 ms 495956 KB Output is correct
9 Correct 120 ms 496468 KB Output is correct
10 Runtime error 461 ms 1005120 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 495908 KB Output is correct
2 Correct 116 ms 495688 KB Output is correct
3 Correct 115 ms 495744 KB Output is correct
4 Correct 115 ms 495696 KB Output is correct
5 Correct 117 ms 495720 KB Output is correct
6 Correct 115 ms 495744 KB Output is correct
7 Correct 118 ms 495700 KB Output is correct
8 Correct 116 ms 495904 KB Output is correct
9 Correct 118 ms 495956 KB Output is correct
10 Correct 119 ms 495828 KB Output is correct
11 Correct 116 ms 495696 KB Output is correct
12 Correct 116 ms 495696 KB Output is correct
13 Correct 114 ms 495816 KB Output is correct
14 Correct 116 ms 495812 KB Output is correct
15 Correct 115 ms 495740 KB Output is correct
16 Correct 123 ms 495952 KB Output is correct
17 Correct 115 ms 495916 KB Output is correct
18 Correct 116 ms 495700 KB Output is correct
19 Correct 117 ms 495700 KB Output is correct
20 Correct 117 ms 495912 KB Output is correct
21 Correct 116 ms 495696 KB Output is correct
22 Correct 115 ms 495664 KB Output is correct
23 Correct 115 ms 495832 KB Output is correct
24 Correct 115 ms 495912 KB Output is correct
25 Correct 116 ms 495952 KB Output is correct
26 Correct 114 ms 495912 KB Output is correct
27 Correct 117 ms 495880 KB Output is correct
28 Correct 115 ms 495852 KB Output is correct
29 Correct 118 ms 495700 KB Output is correct
30 Correct 116 ms 496116 KB Output is correct
31 Correct 115 ms 495844 KB Output is correct
32 Correct 117 ms 496040 KB Output is correct
33 Correct 115 ms 495908 KB Output is correct
34 Correct 115 ms 495700 KB Output is correct
35 Correct 116 ms 495864 KB Output is correct
36 Correct 115 ms 495700 KB Output is correct
37 Correct 122 ms 495952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 495908 KB Output is correct
2 Correct 115 ms 496112 KB Output is correct
3 Correct 120 ms 495872 KB Output is correct
4 Correct 116 ms 495700 KB Output is correct
5 Correct 115 ms 495904 KB Output is correct
6 Correct 117 ms 495696 KB Output is correct
7 Correct 116 ms 495788 KB Output is correct
8 Correct 119 ms 496024 KB Output is correct
9 Correct 115 ms 495924 KB Output is correct
10 Correct 220 ms 537172 KB Output is correct
11 Correct 126 ms 500196 KB Output is correct
12 Correct 156 ms 509776 KB Output is correct
13 Correct 129 ms 500620 KB Output is correct
14 Correct 131 ms 501980 KB Output is correct
15 Correct 128 ms 501652 KB Output is correct
16 Correct 127 ms 501912 KB Output is correct
17 Correct 118 ms 496644 KB Output is correct
18 Correct 128 ms 499540 KB Output is correct
19 Correct 117 ms 496468 KB Output is correct
20 Correct 117 ms 496216 KB Output is correct
21 Correct 130 ms 501584 KB Output is correct
22 Correct 163 ms 514516 KB Output is correct
23 Correct 154 ms 511824 KB Output is correct
24 Correct 140 ms 502612 KB Output is correct
25 Correct 134 ms 502356 KB Output is correct
26 Correct 120 ms 497488 KB Output is correct
27 Correct 118 ms 497236 KB Output is correct
28 Correct 125 ms 499028 KB Output is correct
29 Correct 125 ms 495908 KB Output is correct
30 Correct 116 ms 495688 KB Output is correct
31 Correct 115 ms 495744 KB Output is correct
32 Correct 115 ms 495696 KB Output is correct
33 Correct 117 ms 495720 KB Output is correct
34 Correct 115 ms 495744 KB Output is correct
35 Correct 118 ms 495700 KB Output is correct
36 Correct 116 ms 495904 KB Output is correct
37 Correct 118 ms 495956 KB Output is correct
38 Correct 119 ms 495828 KB Output is correct
39 Correct 116 ms 495696 KB Output is correct
40 Correct 116 ms 495696 KB Output is correct
41 Correct 114 ms 495816 KB Output is correct
42 Correct 116 ms 495812 KB Output is correct
43 Correct 115 ms 495740 KB Output is correct
44 Correct 123 ms 495952 KB Output is correct
45 Correct 115 ms 495916 KB Output is correct
46 Correct 116 ms 495700 KB Output is correct
47 Correct 117 ms 495700 KB Output is correct
48 Correct 117 ms 495912 KB Output is correct
49 Correct 116 ms 495696 KB Output is correct
50 Correct 115 ms 495664 KB Output is correct
51 Correct 115 ms 495832 KB Output is correct
52 Correct 115 ms 495912 KB Output is correct
53 Correct 116 ms 495952 KB Output is correct
54 Correct 114 ms 495912 KB Output is correct
55 Correct 117 ms 495880 KB Output is correct
56 Correct 115 ms 495852 KB Output is correct
57 Correct 118 ms 495700 KB Output is correct
58 Correct 116 ms 496116 KB Output is correct
59 Correct 115 ms 495844 KB Output is correct
60 Correct 117 ms 496040 KB Output is correct
61 Correct 115 ms 495908 KB Output is correct
62 Correct 115 ms 495700 KB Output is correct
63 Correct 116 ms 495864 KB Output is correct
64 Correct 115 ms 495700 KB Output is correct
65 Correct 122 ms 495952 KB Output is correct
66 Correct 116 ms 495868 KB Output is correct
67 Correct 115 ms 495952 KB Output is correct
68 Correct 119 ms 495972 KB Output is correct
69 Correct 118 ms 496164 KB Output is correct
70 Correct 122 ms 496980 KB Output is correct
71 Correct 139 ms 504604 KB Output is correct
72 Correct 131 ms 501876 KB Output is correct
73 Correct 122 ms 496656 KB Output is correct
74 Correct 121 ms 497232 KB Output is correct
75 Correct 138 ms 503968 KB Output is correct
76 Correct 133 ms 502608 KB Output is correct
77 Correct 144 ms 504776 KB Output is correct
78 Correct 133 ms 501912 KB Output is correct
79 Correct 137 ms 503912 KB Output is correct
80 Correct 139 ms 503040 KB Output is correct
81 Correct 128 ms 496976 KB Output is correct
82 Correct 139 ms 505168 KB Output is correct
83 Correct 115 ms 496208 KB Output is correct
84 Correct 152 ms 507628 KB Output is correct
85 Correct 137 ms 502328 KB Output is correct
86 Correct 168 ms 511060 KB Output is correct
87 Correct 156 ms 509776 KB Output is correct
88 Correct 161 ms 510800 KB Output is correct
89 Correct 169 ms 512592 KB Output is correct
90 Correct 154 ms 510048 KB Output is correct
91 Correct 158 ms 510036 KB Output is correct
92 Correct 168 ms 515548 KB Output is correct
93 Correct 168 ms 520424 KB Output is correct
94 Correct 173 ms 517704 KB Output is correct
95 Correct 167 ms 508972 KB Output is correct
96 Correct 143 ms 505680 KB Output is correct
97 Correct 148 ms 506256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 495908 KB Output is correct
2 Correct 115 ms 496112 KB Output is correct
3 Correct 120 ms 495872 KB Output is correct
4 Correct 116 ms 495700 KB Output is correct
5 Correct 115 ms 495904 KB Output is correct
6 Correct 117 ms 495696 KB Output is correct
7 Correct 116 ms 495788 KB Output is correct
8 Correct 119 ms 496024 KB Output is correct
9 Correct 115 ms 495924 KB Output is correct
10 Correct 220 ms 537172 KB Output is correct
11 Correct 126 ms 500196 KB Output is correct
12 Correct 156 ms 509776 KB Output is correct
13 Correct 129 ms 500620 KB Output is correct
14 Correct 131 ms 501980 KB Output is correct
15 Correct 128 ms 501652 KB Output is correct
16 Correct 127 ms 501912 KB Output is correct
17 Correct 118 ms 496644 KB Output is correct
18 Correct 128 ms 499540 KB Output is correct
19 Correct 117 ms 496468 KB Output is correct
20 Correct 117 ms 496216 KB Output is correct
21 Correct 130 ms 501584 KB Output is correct
22 Correct 163 ms 514516 KB Output is correct
23 Correct 154 ms 511824 KB Output is correct
24 Correct 140 ms 502612 KB Output is correct
25 Correct 134 ms 502356 KB Output is correct
26 Correct 120 ms 497488 KB Output is correct
27 Correct 118 ms 497236 KB Output is correct
28 Correct 125 ms 499028 KB Output is correct
29 Correct 125 ms 495908 KB Output is correct
30 Correct 116 ms 495688 KB Output is correct
31 Correct 115 ms 495744 KB Output is correct
32 Correct 115 ms 495696 KB Output is correct
33 Correct 117 ms 495720 KB Output is correct
34 Correct 115 ms 495744 KB Output is correct
35 Correct 118 ms 495700 KB Output is correct
36 Correct 116 ms 495904 KB Output is correct
37 Correct 118 ms 495956 KB Output is correct
38 Correct 119 ms 495828 KB Output is correct
39 Correct 116 ms 495696 KB Output is correct
40 Correct 116 ms 495696 KB Output is correct
41 Correct 114 ms 495816 KB Output is correct
42 Correct 116 ms 495812 KB Output is correct
43 Correct 115 ms 495740 KB Output is correct
44 Correct 123 ms 495952 KB Output is correct
45 Correct 115 ms 495916 KB Output is correct
46 Correct 116 ms 495700 KB Output is correct
47 Correct 117 ms 495700 KB Output is correct
48 Correct 117 ms 495912 KB Output is correct
49 Correct 116 ms 495696 KB Output is correct
50 Correct 115 ms 495664 KB Output is correct
51 Correct 115 ms 495832 KB Output is correct
52 Correct 115 ms 495912 KB Output is correct
53 Correct 116 ms 495952 KB Output is correct
54 Correct 114 ms 495912 KB Output is correct
55 Correct 117 ms 495880 KB Output is correct
56 Correct 115 ms 495852 KB Output is correct
57 Correct 118 ms 495700 KB Output is correct
58 Correct 116 ms 496116 KB Output is correct
59 Correct 115 ms 495844 KB Output is correct
60 Correct 117 ms 496040 KB Output is correct
61 Correct 115 ms 495908 KB Output is correct
62 Correct 115 ms 495700 KB Output is correct
63 Correct 116 ms 495864 KB Output is correct
64 Correct 115 ms 495700 KB Output is correct
65 Correct 122 ms 495952 KB Output is correct
66 Correct 116 ms 495868 KB Output is correct
67 Correct 115 ms 495952 KB Output is correct
68 Correct 119 ms 495972 KB Output is correct
69 Correct 118 ms 496164 KB Output is correct
70 Correct 122 ms 496980 KB Output is correct
71 Correct 139 ms 504604 KB Output is correct
72 Correct 131 ms 501876 KB Output is correct
73 Correct 122 ms 496656 KB Output is correct
74 Correct 121 ms 497232 KB Output is correct
75 Correct 138 ms 503968 KB Output is correct
76 Correct 133 ms 502608 KB Output is correct
77 Correct 144 ms 504776 KB Output is correct
78 Correct 133 ms 501912 KB Output is correct
79 Correct 137 ms 503912 KB Output is correct
80 Correct 139 ms 503040 KB Output is correct
81 Correct 128 ms 496976 KB Output is correct
82 Correct 139 ms 505168 KB Output is correct
83 Correct 115 ms 496208 KB Output is correct
84 Correct 152 ms 507628 KB Output is correct
85 Correct 137 ms 502328 KB Output is correct
86 Correct 168 ms 511060 KB Output is correct
87 Correct 156 ms 509776 KB Output is correct
88 Correct 161 ms 510800 KB Output is correct
89 Correct 169 ms 512592 KB Output is correct
90 Correct 154 ms 510048 KB Output is correct
91 Correct 158 ms 510036 KB Output is correct
92 Correct 168 ms 515548 KB Output is correct
93 Correct 168 ms 520424 KB Output is correct
94 Correct 173 ms 517704 KB Output is correct
95 Correct 167 ms 508972 KB Output is correct
96 Correct 143 ms 505680 KB Output is correct
97 Correct 148 ms 506256 KB Output is correct
98 Correct 117 ms 496472 KB Output is correct
99 Correct 115 ms 495736 KB Output is correct
100 Execution timed out 1070 ms 747148 KB Time limit exceeded
101 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 495908 KB Output is correct
2 Correct 115 ms 496112 KB Output is correct
3 Correct 120 ms 495872 KB Output is correct
4 Correct 116 ms 495700 KB Output is correct
5 Correct 115 ms 495904 KB Output is correct
6 Correct 117 ms 495696 KB Output is correct
7 Correct 116 ms 495788 KB Output is correct
8 Correct 119 ms 496024 KB Output is correct
9 Correct 115 ms 495924 KB Output is correct
10 Correct 220 ms 537172 KB Output is correct
11 Correct 126 ms 500196 KB Output is correct
12 Correct 156 ms 509776 KB Output is correct
13 Correct 129 ms 500620 KB Output is correct
14 Correct 131 ms 501980 KB Output is correct
15 Correct 128 ms 501652 KB Output is correct
16 Correct 127 ms 501912 KB Output is correct
17 Correct 118 ms 496644 KB Output is correct
18 Correct 128 ms 499540 KB Output is correct
19 Correct 117 ms 496468 KB Output is correct
20 Correct 117 ms 496216 KB Output is correct
21 Correct 130 ms 501584 KB Output is correct
22 Correct 163 ms 514516 KB Output is correct
23 Correct 154 ms 511824 KB Output is correct
24 Correct 140 ms 502612 KB Output is correct
25 Correct 134 ms 502356 KB Output is correct
26 Correct 120 ms 497488 KB Output is correct
27 Correct 118 ms 497236 KB Output is correct
28 Correct 125 ms 499028 KB Output is correct
29 Correct 116 ms 496084 KB Output is correct
30 Correct 117 ms 495700 KB Output is correct
31 Correct 117 ms 495896 KB Output is correct
32 Correct 117 ms 495828 KB Output is correct
33 Correct 121 ms 495936 KB Output is correct
34 Correct 116 ms 495884 KB Output is correct
35 Correct 126 ms 495728 KB Output is correct
36 Correct 117 ms 495956 KB Output is correct
37 Correct 120 ms 496468 KB Output is correct
38 Runtime error 461 ms 1005120 KB Execution killed with signal 11
39 Halted 0 ms 0 KB -