Submission #1035977

# Submission time Handle Problem Language Result Execution time Memory
1035977 2024-07-26T23:37:11 Z tvladm2009 Cookies (JOI23_cookies) C++17
12 / 100
221 ms 431228 KB
#include <bits/stdc++.h>
 
using namespace std;

typedef long long ll;

const int N = 3000 + 7;

int n, m, a[N], b[N];
int vertical[N];

struct MyBitset {
    vector<ll> b;

    void resize(int n) {
        b.resize(n / 63 + 1, 0);
    }

    void set(int x) {
        b[(x - 1) / 63] |= (1LL << (x % 63));
    }

    bool get(int x) {
        if (b[(x - 1) / 63] & (1LL << (x % 63))) {
            return true;
        } else {
            return false;
        }
    }
};

MyBitset dp[N][N];

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    cin >> m;
    for (int i = 1; i <= m; ++i) cin >> b[i];
    
    int sumA = 0;
    for (int i = 1; i <= n; ++i) {
        sumA += a[i];
    }
    reverse(b + 1, b + m + 1);
    for (int i = 1; i <= sumA; ++i) {
        for (int j = 1; j <= n; ++j) {
            vertical[i] += min(i, a[j]);
        }
    }
    for (int sum = 0; sum <= sumA; ++sum) {
        dp[0][sum].resize(sum);
    }
    dp[0][0].set(0);
    for (int i = 1; i <= m; ++i) {
        for (int sum = 0; sum <= sumA; ++sum) {
            dp[i][sum].resize(sum / b[i]);
        }
        for (int sum = 0; sum <= sumA; ++sum) {
            for (int x = 0; x <= sum / b[i]; ++x) {
                if (vertical[x] >= sum) {
                    bool b1 = (x == 0 ? 0 : dp[i][sum - b[i]].get(x - 1));
                    bool b2 = dp[i - 1][sum].get(x);
                    if (b1 | b2) {
                        dp[i][sum].set(x);
                    }
                    // dp[i][sum][x] = dp[i][x - 1][sum - b[i]] | dp[i - 1][x][sum];
                }
            }
        }
    }
    for (int x = 1; x <= sumA / b[m]; ++x) {
        if (dp[m][sumA].get(x) == true) {
            cout << x << "\n";
            vector<pair<int, int>> boxes;
            int cnt = x;
            int sum = sumA;
            int pos = m;
            while (pos > 0) {
                if (cnt != 0 && dp[pos][sum - b[pos]].get(cnt - 1)) {
                    boxes.push_back({b[pos], boxes.size()});
                    sum -= b[pos];
                    cnt--;
                } else {
                    assert(dp[pos - 1][sum].get(cnt) == 1);
                    pos--;
                }
            }
            vector<vector<int>> sol(boxes.size());
            for (int i = 1; i <= n; ++i) {
                sort(boxes.rbegin(), boxes.rend());
                int j = 0;
                while (a[i] > 0) {
                    if (j == boxes.size()) {
                        cout << i << "\n";
                        return 0;
                    }
                    if (boxes[j].first > 0) {
                        sol[boxes[j].second].push_back(i);
                        boxes[j].first--;
                        a[i]--;
                    }
                    j++;
                }
            }
            for (int i = 0; i < boxes.size(); ++i) {
                cout << sol[i].size() << " ";
                for (auto j : sol[i]) {
                    cout << j << " ";
                }
                cout << "\n";
            }
            return 0;
        }
    }
    cout << -1 << "\n";
    return 0;
}

Compilation message

cookies.cpp: In function 'int main()':
cookies.cpp:95:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |                     if (j == boxes.size()) {
      |                         ~~^~~~~~~~~~~~~~~
cookies.cpp:107:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |             for (int i = 0; i < boxes.size(); ++i) {
      |                             ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 76 ms 212564 KB Output is correct
2 Correct 78 ms 212676 KB Output is correct
3 Correct 80 ms 212772 KB Output is correct
4 Correct 79 ms 212600 KB Output is correct
5 Correct 78 ms 212564 KB Output is correct
6 Correct 77 ms 212756 KB Output is correct
7 Correct 76 ms 212648 KB Output is correct
8 Runtime error 221 ms 431184 KB Execution killed with signal 6
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 73 ms 212560 KB Output is correct
2 Correct 74 ms 212760 KB Output is correct
3 Correct 78 ms 212552 KB Output is correct
4 Correct 78 ms 212564 KB Output is correct
5 Runtime error 208 ms 431228 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 212560 KB Output is correct
2 Correct 82 ms 212564 KB Output is correct
3 Correct 79 ms 212624 KB Output is correct
4 Correct 79 ms 212560 KB Output is correct
5 Correct 80 ms 212564 KB Output is correct
6 Correct 78 ms 212564 KB Output is correct
7 Correct 82 ms 212564 KB Output is correct
8 Correct 75 ms 212560 KB Output is correct
9 Correct 76 ms 212560 KB Output is correct
10 Correct 81 ms 212624 KB Output is correct
11 Correct 78 ms 212772 KB Output is correct
12 Correct 78 ms 212560 KB Output is correct
13 Correct 77 ms 212560 KB Output is correct
14 Correct 76 ms 212560 KB Output is correct
15 Correct 76 ms 212564 KB Output is correct
16 Correct 75 ms 212544 KB Output is correct
17 Correct 78 ms 212760 KB Output is correct
18 Correct 79 ms 212768 KB Output is correct
19 Correct 77 ms 212560 KB Output is correct
20 Correct 77 ms 212612 KB Output is correct
21 Correct 78 ms 212684 KB Output is correct
22 Correct 76 ms 212816 KB Output is correct
23 Correct 81 ms 212632 KB Output is correct
24 Correct 77 ms 212560 KB Output is correct
25 Correct 78 ms 212560 KB Output is correct
26 Correct 75 ms 212564 KB Output is correct
27 Correct 77 ms 212564 KB Output is correct
28 Correct 80 ms 212560 KB Output is correct
29 Correct 76 ms 212560 KB Output is correct
30 Correct 77 ms 212592 KB Output is correct
31 Correct 77 ms 212528 KB Output is correct
32 Correct 76 ms 212560 KB Output is correct
33 Correct 79 ms 212576 KB Output is correct
34 Correct 75 ms 212776 KB Output is correct
35 Correct 78 ms 212560 KB Output is correct
36 Correct 76 ms 212564 KB Output is correct
37 Correct 82 ms 212768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 212564 KB Output is correct
2 Correct 78 ms 212676 KB Output is correct
3 Correct 80 ms 212772 KB Output is correct
4 Correct 79 ms 212600 KB Output is correct
5 Correct 78 ms 212564 KB Output is correct
6 Correct 77 ms 212756 KB Output is correct
7 Correct 76 ms 212648 KB Output is correct
8 Runtime error 221 ms 431184 KB Execution killed with signal 6
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 76 ms 212564 KB Output is correct
2 Correct 78 ms 212676 KB Output is correct
3 Correct 80 ms 212772 KB Output is correct
4 Correct 79 ms 212600 KB Output is correct
5 Correct 78 ms 212564 KB Output is correct
6 Correct 77 ms 212756 KB Output is correct
7 Correct 76 ms 212648 KB Output is correct
8 Runtime error 221 ms 431184 KB Execution killed with signal 6
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 76 ms 212564 KB Output is correct
2 Correct 78 ms 212676 KB Output is correct
3 Correct 80 ms 212772 KB Output is correct
4 Correct 79 ms 212600 KB Output is correct
5 Correct 78 ms 212564 KB Output is correct
6 Correct 77 ms 212756 KB Output is correct
7 Correct 76 ms 212648 KB Output is correct
8 Runtime error 221 ms 431184 KB Execution killed with signal 6
9 Halted 0 ms 0 KB -