Submission #789242

# Submission time Handle Problem Language Result Execution time Memory
789242 2023-07-21T08:34:46 Z 이동현(#10044) Cookies (JOI23_cookies) C++17
0 / 100
24 ms 13192 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 = 19;
int n, m;
int a[NS], b[NS];
int mn[NS];
bool dp[NS][SZ][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';
    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){
            --srt[j].first;
            cout << srt[j].second << ' ';
        }
        cout << '\n';
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 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 Incorrect 1 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 22 ms 13192 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 24 ms 13188 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 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 Incorrect 1 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 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 Incorrect 1 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 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 Incorrect 1 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -