답안 #789317

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
789317 2023-07-21T09:11:27 Z 이동현(#10044) Cookies (JOI23_cookies) C++17
6 / 100
161 ms 2520 KB
#include <bits/stdc++.h>
#define int long long
#define mi(x, y) (x = min(x, y))
#define ma(x, y) (x = max(x, y))
using namespace std;

const int NS = 15004;
const int SZ = 504;
int n, m;
int a[NS], b[NS];
int mn[NS];
bitset<504> dp[NS][SZ];
pair<int, int> srt[NS];

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    int asum = 0;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        srt[i] = {a[i], i};
        asum += a[i];
    }
    cin >> m;
    for(int i = 1; i <= m; ++i){
        cin >> b[i];
    }

    sort(b + 1, b + m + 1);
    reverse(b + 1, b + m + 1);

    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= n; ++j){
            mn[i] += min(i, a[j]);
        }
        mn[i] = min(mn[i], 500ll);
    }

    dp[0][0][0] = 1;
    for(int i = 1; i <= m; ++i){
        for(int j = 0; j <= SZ - 4; ++j){
            for(int k = 0; k <= mn[j]; ++k){
                if(dp[i - 1][j][k]){
                    dp[i][j][k] = 1;
                }
                if(j && k >= b[i] && dp[i][j - 1][k - b[i]]){
                    dp[i][j][k] = 1;
                }
            }
        }
    }

    int ans = -1;
    for(int i = 1; i <= SZ - 4; ++i){
        if(dp[m][i][asum]){
            ans = i;
            break;
        }
    }

    cout << ans << '\n';
    if(ans == -1){
        return 0;
    }
    vector<int> lst;
    auto makelst = [&](auto&&self, int i, int j, int k)->void{
        if(!i) return;
        if(dp[i - 1][j][k]){
            self(self, i - 1, j, k);
        }
        else{
            self(self, i, j - 1, k - b[i]);
            lst.push_back(b[i]);
        }
    };
    makelst(makelst, m, ans, asum);

    for(auto&i:lst){
        cout << i << ' ';
        sort(srt + 1, srt + n + 1);
        reverse(srt + 1, srt + n + 1);
        while(!srt[n].first){
            --n;
        }

        for(int j = 1; j <= i; ++j){
            assert(srt[j].first >= 1);
            --srt[j].first;
            cout << srt[j].second << ' ';
        }
        cout << '\n';
    }

    assert(srt[0].first == 0);
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 161 ms 2520 KB Output is correct
11 Correct 71 ms 1344 KB Output is correct
12 Correct 18 ms 636 KB Output is correct
13 Correct 39 ms 768 KB Output is correct
14 Correct 84 ms 1200 KB Output is correct
15 Correct 65 ms 1232 KB Output is correct
16 Correct 74 ms 1404 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 4 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 4 ms 360 KB Output is correct
21 Correct 33 ms 672 KB Output is correct
22 Correct 80 ms 1360 KB Output is correct
23 Correct 84 ms 1408 KB Output is correct
24 Correct 10 ms 468 KB Output is correct
25 Correct 10 ms 468 KB Output is correct
26 Correct 10 ms 468 KB Output is correct
27 Correct 10 ms 468 KB Output is correct
28 Correct 42 ms 908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Incorrect 0 ms 340 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Incorrect 0 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 161 ms 2520 KB Output is correct
11 Correct 71 ms 1344 KB Output is correct
12 Correct 18 ms 636 KB Output is correct
13 Correct 39 ms 768 KB Output is correct
14 Correct 84 ms 1200 KB Output is correct
15 Correct 65 ms 1232 KB Output is correct
16 Correct 74 ms 1404 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 4 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 4 ms 360 KB Output is correct
21 Correct 33 ms 672 KB Output is correct
22 Correct 80 ms 1360 KB Output is correct
23 Correct 84 ms 1408 KB Output is correct
24 Correct 10 ms 468 KB Output is correct
25 Correct 10 ms 468 KB Output is correct
26 Correct 10 ms 468 KB Output is correct
27 Correct 10 ms 468 KB Output is correct
28 Correct 42 ms 908 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Incorrect 0 ms 340 KB Output isn't correct
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 161 ms 2520 KB Output is correct
11 Correct 71 ms 1344 KB Output is correct
12 Correct 18 ms 636 KB Output is correct
13 Correct 39 ms 768 KB Output is correct
14 Correct 84 ms 1200 KB Output is correct
15 Correct 65 ms 1232 KB Output is correct
16 Correct 74 ms 1404 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 4 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 4 ms 360 KB Output is correct
21 Correct 33 ms 672 KB Output is correct
22 Correct 80 ms 1360 KB Output is correct
23 Correct 84 ms 1408 KB Output is correct
24 Correct 10 ms 468 KB Output is correct
25 Correct 10 ms 468 KB Output is correct
26 Correct 10 ms 468 KB Output is correct
27 Correct 10 ms 468 KB Output is correct
28 Correct 42 ms 908 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Incorrect 0 ms 340 KB Output isn't correct
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 161 ms 2520 KB Output is correct
11 Correct 71 ms 1344 KB Output is correct
12 Correct 18 ms 636 KB Output is correct
13 Correct 39 ms 768 KB Output is correct
14 Correct 84 ms 1200 KB Output is correct
15 Correct 65 ms 1232 KB Output is correct
16 Correct 74 ms 1404 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 4 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 4 ms 360 KB Output is correct
21 Correct 33 ms 672 KB Output is correct
22 Correct 80 ms 1360 KB Output is correct
23 Correct 84 ms 1408 KB Output is correct
24 Correct 10 ms 468 KB Output is correct
25 Correct 10 ms 468 KB Output is correct
26 Correct 10 ms 468 KB Output is correct
27 Correct 10 ms 468 KB Output is correct
28 Correct 42 ms 908 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Incorrect 0 ms 340 KB Output isn't correct
36 Halted 0 ms 0 KB -