답안 #1037832

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1037832 2024-07-29T08:59:48 Z 정희우(#10983) Cookies (JOI23_cookies) C++17
63 / 100
326 ms 519808 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;
using lint = long long;
using intp = pair<int,int>;
using vint = vector<int>;

const int MAX_N=510;

int n,m;
int arr[MAX_N],sarr[MAX_N],sum[MAX_N];
int box[MAX_N];
int dt[MAX_N][MAX_N][MAX_N];
priority_queue<intp> pq;

int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> arr[i];
        sarr[i]=arr[i];
    }
    sort(sarr,sarr+n,greater<int>());
    for(int i=0;i<n;i++)
        sum[i]=sarr[i]+((i) ? sum[i-1] : 0);
    cin >> m;
    for(int i=1;i<=m;i++)
        cin >> box[i];
    fill(dt[0][0],dt[0][0]+MAX_N*MAX_N*MAX_N,MAX_N);
    for(int i=sarr[0];i<=sum[n-1];i++)dt[0][i][0]=i;
    for(int b=1;b<=m;b++)
        for(int h=sum[n-1];h>=0;h--)
            for(int s=0;s<=sum[n-1];s++)
            {
                dt[b][h][s]=dt[b][h+1][s];
                int flag=1;
                for(int v=box[b-1]+1;v<=box[b];v++)
                    if(s-h*(box[b]-v)<sum[v-1])flag=0;
                if(flag && s-h*(box[b]-box[b-1])>=0)
                    dt[b][h][s]=min(dt[b][h][s],dt[b-1][h][s-h*(box[b]-box[b-1])]);
            }
    if(dt[m][0][sum[n-1]]==MAX_N)
    {
        cout << -1;
        return 0;
    }
    cout << dt[m][0][sum[n-1]] << '\n';
    vint boxs;
    for(int b=m,h=0,s=sum[n-1];b+s>0;)
    {
        if(dt[b][h][s]==dt[b][h+1][s])
        {
            boxs.push_back(box[b]);
            h++;
        }
        else
        {
            s-=h*(box[b]-box[b-1]);
            b--;
        }
    }
    for(int i=0;i<n;i++)
        pq.push({arr[i],i+1});
    vector<intp> st;
    for(auto c : boxs)
    {
        cout << c << ' ';
        for(int i=0;i<c;i++)
        {
            intp p=pq.top();pq.pop();
            cout << p.second << ' ';
            st.push_back({p.first-1,p.second});
        }
        while(!st.empty())
        {
            pq.push(st.back());
            st.pop_back();
        }
        cout << '\n';
    }
    /*for(int b=0;b<=m;b++)
    {
        cout << b << ":\n";
        for(int h=0;h<=sum[n-1];h++,cout << '\n')
            for(int s=0;s<=sum[n-1];s++)
                cout << dt[b][h][s] << ' ';
    }*/
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 519504 KB Output is correct
2 Correct 114 ms 519504 KB Output is correct
3 Correct 112 ms 519604 KB Output is correct
4 Correct 114 ms 519460 KB Output is correct
5 Correct 110 ms 519504 KB Output is correct
6 Correct 133 ms 519616 KB Output is correct
7 Correct 121 ms 519504 KB Output is correct
8 Correct 141 ms 519416 KB Output is correct
9 Correct 212 ms 519480 KB Output is correct
10 Correct 326 ms 519616 KB Output is correct
11 Correct 265 ms 519588 KB Output is correct
12 Correct 157 ms 519620 KB Output is correct
13 Correct 242 ms 519420 KB Output is correct
14 Correct 246 ms 519620 KB Output is correct
15 Correct 258 ms 519540 KB Output is correct
16 Correct 274 ms 519624 KB Output is correct
17 Correct 122 ms 519504 KB Output is correct
18 Correct 132 ms 519392 KB Output is correct
19 Correct 141 ms 519512 KB Output is correct
20 Correct 197 ms 519420 KB Output is correct
21 Correct 217 ms 519504 KB Output is correct
22 Correct 231 ms 519504 KB Output is correct
23 Correct 266 ms 519388 KB Output is correct
24 Correct 195 ms 519512 KB Output is correct
25 Correct 185 ms 519464 KB Output is correct
26 Correct 190 ms 519504 KB Output is correct
27 Correct 220 ms 519572 KB Output is correct
28 Correct 241 ms 519628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 519396 KB Output is correct
2 Correct 119 ms 519576 KB Output is correct
3 Correct 115 ms 519564 KB Output is correct
4 Correct 102 ms 519532 KB Output is correct
5 Correct 119 ms 519504 KB Output is correct
6 Correct 201 ms 519624 KB Output is correct
7 Correct 107 ms 519388 KB Output is correct
8 Correct 106 ms 519508 KB Output is correct
9 Incorrect 146 ms 519504 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 519504 KB Output is correct
2 Correct 111 ms 519452 KB Output is correct
3 Correct 112 ms 519504 KB Output is correct
4 Correct 120 ms 519604 KB Output is correct
5 Correct 111 ms 519592 KB Output is correct
6 Correct 110 ms 519504 KB Output is correct
7 Correct 111 ms 519456 KB Output is correct
8 Correct 112 ms 519504 KB Output is correct
9 Correct 130 ms 519512 KB Output is correct
10 Correct 111 ms 519508 KB Output is correct
11 Correct 112 ms 519384 KB Output is correct
12 Correct 129 ms 519508 KB Output is correct
13 Correct 110 ms 519508 KB Output is correct
14 Correct 111 ms 519452 KB Output is correct
15 Correct 115 ms 519484 KB Output is correct
16 Correct 110 ms 519808 KB Output is correct
17 Correct 112 ms 519560 KB Output is correct
18 Correct 107 ms 519500 KB Output is correct
19 Correct 108 ms 519400 KB Output is correct
20 Correct 114 ms 519504 KB Output is correct
21 Correct 124 ms 519412 KB Output is correct
22 Correct 108 ms 519416 KB Output is correct
23 Correct 108 ms 519508 KB Output is correct
24 Correct 109 ms 519504 KB Output is correct
25 Correct 112 ms 519476 KB Output is correct
26 Correct 110 ms 519464 KB Output is correct
27 Correct 111 ms 519600 KB Output is correct
28 Correct 110 ms 519504 KB Output is correct
29 Correct 105 ms 519508 KB Output is correct
30 Correct 140 ms 519404 KB Output is correct
31 Correct 111 ms 519508 KB Output is correct
32 Correct 114 ms 519504 KB Output is correct
33 Correct 111 ms 519504 KB Output is correct
34 Correct 112 ms 519528 KB Output is correct
35 Correct 112 ms 519560 KB Output is correct
36 Correct 117 ms 519504 KB Output is correct
37 Correct 111 ms 519572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 519504 KB Output is correct
2 Correct 114 ms 519504 KB Output is correct
3 Correct 112 ms 519604 KB Output is correct
4 Correct 114 ms 519460 KB Output is correct
5 Correct 110 ms 519504 KB Output is correct
6 Correct 133 ms 519616 KB Output is correct
7 Correct 121 ms 519504 KB Output is correct
8 Correct 141 ms 519416 KB Output is correct
9 Correct 212 ms 519480 KB Output is correct
10 Correct 326 ms 519616 KB Output is correct
11 Correct 265 ms 519588 KB Output is correct
12 Correct 157 ms 519620 KB Output is correct
13 Correct 242 ms 519420 KB Output is correct
14 Correct 246 ms 519620 KB Output is correct
15 Correct 258 ms 519540 KB Output is correct
16 Correct 274 ms 519624 KB Output is correct
17 Correct 122 ms 519504 KB Output is correct
18 Correct 132 ms 519392 KB Output is correct
19 Correct 141 ms 519512 KB Output is correct
20 Correct 197 ms 519420 KB Output is correct
21 Correct 217 ms 519504 KB Output is correct
22 Correct 231 ms 519504 KB Output is correct
23 Correct 266 ms 519388 KB Output is correct
24 Correct 195 ms 519512 KB Output is correct
25 Correct 185 ms 519464 KB Output is correct
26 Correct 190 ms 519504 KB Output is correct
27 Correct 220 ms 519572 KB Output is correct
28 Correct 241 ms 519628 KB Output is correct
29 Correct 113 ms 519504 KB Output is correct
30 Correct 111 ms 519452 KB Output is correct
31 Correct 112 ms 519504 KB Output is correct
32 Correct 120 ms 519604 KB Output is correct
33 Correct 111 ms 519592 KB Output is correct
34 Correct 110 ms 519504 KB Output is correct
35 Correct 111 ms 519456 KB Output is correct
36 Correct 112 ms 519504 KB Output is correct
37 Correct 130 ms 519512 KB Output is correct
38 Correct 111 ms 519508 KB Output is correct
39 Correct 112 ms 519384 KB Output is correct
40 Correct 129 ms 519508 KB Output is correct
41 Correct 110 ms 519508 KB Output is correct
42 Correct 111 ms 519452 KB Output is correct
43 Correct 115 ms 519484 KB Output is correct
44 Correct 110 ms 519808 KB Output is correct
45 Correct 112 ms 519560 KB Output is correct
46 Correct 107 ms 519500 KB Output is correct
47 Correct 108 ms 519400 KB Output is correct
48 Correct 114 ms 519504 KB Output is correct
49 Correct 124 ms 519412 KB Output is correct
50 Correct 108 ms 519416 KB Output is correct
51 Correct 108 ms 519508 KB Output is correct
52 Correct 109 ms 519504 KB Output is correct
53 Correct 112 ms 519476 KB Output is correct
54 Correct 110 ms 519464 KB Output is correct
55 Correct 111 ms 519600 KB Output is correct
56 Correct 110 ms 519504 KB Output is correct
57 Correct 105 ms 519508 KB Output is correct
58 Correct 140 ms 519404 KB Output is correct
59 Correct 111 ms 519508 KB Output is correct
60 Correct 114 ms 519504 KB Output is correct
61 Correct 111 ms 519504 KB Output is correct
62 Correct 112 ms 519528 KB Output is correct
63 Correct 112 ms 519560 KB Output is correct
64 Correct 117 ms 519504 KB Output is correct
65 Correct 111 ms 519572 KB Output is correct
66 Correct 112 ms 519608 KB Output is correct
67 Correct 110 ms 519432 KB Output is correct
68 Correct 109 ms 519428 KB Output is correct
69 Correct 103 ms 519400 KB Output is correct
70 Correct 136 ms 519396 KB Output is correct
71 Correct 143 ms 519500 KB Output is correct
72 Correct 160 ms 519484 KB Output is correct
73 Correct 150 ms 519592 KB Output is correct
74 Correct 168 ms 519508 KB Output is correct
75 Correct 175 ms 519504 KB Output is correct
76 Correct 123 ms 519572 KB Output is correct
77 Correct 120 ms 519504 KB Output is correct
78 Correct 119 ms 519504 KB Output is correct
79 Correct 121 ms 519456 KB Output is correct
80 Correct 115 ms 519372 KB Output is correct
81 Correct 118 ms 519392 KB Output is correct
82 Correct 144 ms 519572 KB Output is correct
83 Correct 136 ms 519544 KB Output is correct
84 Correct 154 ms 519504 KB Output is correct
85 Correct 113 ms 519532 KB Output is correct
86 Correct 126 ms 519480 KB Output is correct
87 Correct 136 ms 519580 KB Output is correct
88 Correct 134 ms 519508 KB Output is correct
89 Correct 137 ms 519508 KB Output is correct
90 Correct 153 ms 519504 KB Output is correct
91 Correct 158 ms 519508 KB Output is correct
92 Correct 152 ms 519504 KB Output is correct
93 Correct 294 ms 519504 KB Output is correct
94 Correct 233 ms 519504 KB Output is correct
95 Correct 117 ms 519576 KB Output is correct
96 Correct 118 ms 519612 KB Output is correct
97 Correct 148 ms 519504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 519504 KB Output is correct
2 Correct 114 ms 519504 KB Output is correct
3 Correct 112 ms 519604 KB Output is correct
4 Correct 114 ms 519460 KB Output is correct
5 Correct 110 ms 519504 KB Output is correct
6 Correct 133 ms 519616 KB Output is correct
7 Correct 121 ms 519504 KB Output is correct
8 Correct 141 ms 519416 KB Output is correct
9 Correct 212 ms 519480 KB Output is correct
10 Correct 326 ms 519616 KB Output is correct
11 Correct 265 ms 519588 KB Output is correct
12 Correct 157 ms 519620 KB Output is correct
13 Correct 242 ms 519420 KB Output is correct
14 Correct 246 ms 519620 KB Output is correct
15 Correct 258 ms 519540 KB Output is correct
16 Correct 274 ms 519624 KB Output is correct
17 Correct 122 ms 519504 KB Output is correct
18 Correct 132 ms 519392 KB Output is correct
19 Correct 141 ms 519512 KB Output is correct
20 Correct 197 ms 519420 KB Output is correct
21 Correct 217 ms 519504 KB Output is correct
22 Correct 231 ms 519504 KB Output is correct
23 Correct 266 ms 519388 KB Output is correct
24 Correct 195 ms 519512 KB Output is correct
25 Correct 185 ms 519464 KB Output is correct
26 Correct 190 ms 519504 KB Output is correct
27 Correct 220 ms 519572 KB Output is correct
28 Correct 241 ms 519628 KB Output is correct
29 Correct 113 ms 519504 KB Output is correct
30 Correct 111 ms 519452 KB Output is correct
31 Correct 112 ms 519504 KB Output is correct
32 Correct 120 ms 519604 KB Output is correct
33 Correct 111 ms 519592 KB Output is correct
34 Correct 110 ms 519504 KB Output is correct
35 Correct 111 ms 519456 KB Output is correct
36 Correct 112 ms 519504 KB Output is correct
37 Correct 130 ms 519512 KB Output is correct
38 Correct 111 ms 519508 KB Output is correct
39 Correct 112 ms 519384 KB Output is correct
40 Correct 129 ms 519508 KB Output is correct
41 Correct 110 ms 519508 KB Output is correct
42 Correct 111 ms 519452 KB Output is correct
43 Correct 115 ms 519484 KB Output is correct
44 Correct 110 ms 519808 KB Output is correct
45 Correct 112 ms 519560 KB Output is correct
46 Correct 107 ms 519500 KB Output is correct
47 Correct 108 ms 519400 KB Output is correct
48 Correct 114 ms 519504 KB Output is correct
49 Correct 124 ms 519412 KB Output is correct
50 Correct 108 ms 519416 KB Output is correct
51 Correct 108 ms 519508 KB Output is correct
52 Correct 109 ms 519504 KB Output is correct
53 Correct 112 ms 519476 KB Output is correct
54 Correct 110 ms 519464 KB Output is correct
55 Correct 111 ms 519600 KB Output is correct
56 Correct 110 ms 519504 KB Output is correct
57 Correct 105 ms 519508 KB Output is correct
58 Correct 140 ms 519404 KB Output is correct
59 Correct 111 ms 519508 KB Output is correct
60 Correct 114 ms 519504 KB Output is correct
61 Correct 111 ms 519504 KB Output is correct
62 Correct 112 ms 519528 KB Output is correct
63 Correct 112 ms 519560 KB Output is correct
64 Correct 117 ms 519504 KB Output is correct
65 Correct 111 ms 519572 KB Output is correct
66 Correct 112 ms 519608 KB Output is correct
67 Correct 110 ms 519432 KB Output is correct
68 Correct 109 ms 519428 KB Output is correct
69 Correct 103 ms 519400 KB Output is correct
70 Correct 136 ms 519396 KB Output is correct
71 Correct 143 ms 519500 KB Output is correct
72 Correct 160 ms 519484 KB Output is correct
73 Correct 150 ms 519592 KB Output is correct
74 Correct 168 ms 519508 KB Output is correct
75 Correct 175 ms 519504 KB Output is correct
76 Correct 123 ms 519572 KB Output is correct
77 Correct 120 ms 519504 KB Output is correct
78 Correct 119 ms 519504 KB Output is correct
79 Correct 121 ms 519456 KB Output is correct
80 Correct 115 ms 519372 KB Output is correct
81 Correct 118 ms 519392 KB Output is correct
82 Correct 144 ms 519572 KB Output is correct
83 Correct 136 ms 519544 KB Output is correct
84 Correct 154 ms 519504 KB Output is correct
85 Correct 113 ms 519532 KB Output is correct
86 Correct 126 ms 519480 KB Output is correct
87 Correct 136 ms 519580 KB Output is correct
88 Correct 134 ms 519508 KB Output is correct
89 Correct 137 ms 519508 KB Output is correct
90 Correct 153 ms 519504 KB Output is correct
91 Correct 158 ms 519508 KB Output is correct
92 Correct 152 ms 519504 KB Output is correct
93 Correct 294 ms 519504 KB Output is correct
94 Correct 233 ms 519504 KB Output is correct
95 Correct 117 ms 519576 KB Output is correct
96 Correct 118 ms 519612 KB Output is correct
97 Correct 148 ms 519504 KB Output is correct
98 Incorrect 123 ms 519420 KB Output isn't correct
99 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 519504 KB Output is correct
2 Correct 114 ms 519504 KB Output is correct
3 Correct 112 ms 519604 KB Output is correct
4 Correct 114 ms 519460 KB Output is correct
5 Correct 110 ms 519504 KB Output is correct
6 Correct 133 ms 519616 KB Output is correct
7 Correct 121 ms 519504 KB Output is correct
8 Correct 141 ms 519416 KB Output is correct
9 Correct 212 ms 519480 KB Output is correct
10 Correct 326 ms 519616 KB Output is correct
11 Correct 265 ms 519588 KB Output is correct
12 Correct 157 ms 519620 KB Output is correct
13 Correct 242 ms 519420 KB Output is correct
14 Correct 246 ms 519620 KB Output is correct
15 Correct 258 ms 519540 KB Output is correct
16 Correct 274 ms 519624 KB Output is correct
17 Correct 122 ms 519504 KB Output is correct
18 Correct 132 ms 519392 KB Output is correct
19 Correct 141 ms 519512 KB Output is correct
20 Correct 197 ms 519420 KB Output is correct
21 Correct 217 ms 519504 KB Output is correct
22 Correct 231 ms 519504 KB Output is correct
23 Correct 266 ms 519388 KB Output is correct
24 Correct 195 ms 519512 KB Output is correct
25 Correct 185 ms 519464 KB Output is correct
26 Correct 190 ms 519504 KB Output is correct
27 Correct 220 ms 519572 KB Output is correct
28 Correct 241 ms 519628 KB Output is correct
29 Correct 125 ms 519396 KB Output is correct
30 Correct 119 ms 519576 KB Output is correct
31 Correct 115 ms 519564 KB Output is correct
32 Correct 102 ms 519532 KB Output is correct
33 Correct 119 ms 519504 KB Output is correct
34 Correct 201 ms 519624 KB Output is correct
35 Correct 107 ms 519388 KB Output is correct
36 Correct 106 ms 519508 KB Output is correct
37 Incorrect 146 ms 519504 KB Output isn't correct
38 Halted 0 ms 0 KB -