답안 #1035992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1035992 2024-07-27T00:23:45 Z tvladm2009 Cookies (JOI23_cookies) C++17
6 / 100
75 ms 16812 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
const int N = 3000 + 7;
const int M = 15000 + 7;
 
int n, m, a[M], b[M];
int vertical[M];
 
struct MyBitset {
    vector<ll> b;
    int n;
 
    void resize(int nn) {
        n = nn;
        b.resize(n / 63 + 2, 0);
    }
 
    void set(int x) {
        b[x / 63] |= (1LL << (x % 63));
    }
 
    bool get(int x) {
        if (x > n) {
            return 0;
        }
        if (b[x / 63] & (1LL << (x % 63))) {
            return true;
        } else {
            return false;
        }
    }
};
 
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]);
        }
    }
    vector<vector<MyBitset>> dp(m + 1, vector<MyBitset>(sumA + 1));
 
    dp[0][0].resize(1);
    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());
            sort(boxes.rbegin(), boxes.rend());
            int last = 0;
            for (int i = 1; i <= n; ++i) {
                int j = last;
                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]--;
                    } else {
                        last = max(last, j);
                    }
                    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:100: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]
  100 |                     if (j == boxes.size()) {
      |                         ~~^~~~~~~~~~~~~~~
cookies.cpp:114: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]
  114 |             for (int i = 0; i < boxes.size(); ++i) {
      |                             ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 372 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 19 ms 15964 KB Output is correct
11 Correct 8 ms 8284 KB Output is correct
12 Correct 4 ms 1884 KB Output is correct
13 Correct 5 ms 4444 KB Output is correct
14 Correct 8 ms 7516 KB Output is correct
15 Correct 8 ms 7272 KB Output is correct
16 Correct 8 ms 8028 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 4 ms 3420 KB Output is correct
22 Correct 9 ms 8280 KB Output is correct
23 Correct 10 ms 8284 KB Output is correct
24 Correct 2 ms 1372 KB Output is correct
25 Correct 2 ms 1400 KB Output is correct
26 Correct 2 ms 1372 KB Output is correct
27 Correct 1 ms 1372 KB Output is correct
28 Correct 5 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 4 ms 1372 KB Output is correct
10 Correct 75 ms 16812 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 372 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 19 ms 15964 KB Output is correct
11 Correct 8 ms 8284 KB Output is correct
12 Correct 4 ms 1884 KB Output is correct
13 Correct 5 ms 4444 KB Output is correct
14 Correct 8 ms 7516 KB Output is correct
15 Correct 8 ms 7272 KB Output is correct
16 Correct 8 ms 8028 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 4 ms 3420 KB Output is correct
22 Correct 9 ms 8280 KB Output is correct
23 Correct 10 ms 8284 KB Output is correct
24 Correct 2 ms 1372 KB Output is correct
25 Correct 2 ms 1400 KB Output is correct
26 Correct 2 ms 1372 KB Output is correct
27 Correct 1 ms 1372 KB Output is correct
28 Correct 5 ms 4956 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 372 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 19 ms 15964 KB Output is correct
11 Correct 8 ms 8284 KB Output is correct
12 Correct 4 ms 1884 KB Output is correct
13 Correct 5 ms 4444 KB Output is correct
14 Correct 8 ms 7516 KB Output is correct
15 Correct 8 ms 7272 KB Output is correct
16 Correct 8 ms 8028 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 4 ms 3420 KB Output is correct
22 Correct 9 ms 8280 KB Output is correct
23 Correct 10 ms 8284 KB Output is correct
24 Correct 2 ms 1372 KB Output is correct
25 Correct 2 ms 1400 KB Output is correct
26 Correct 2 ms 1372 KB Output is correct
27 Correct 1 ms 1372 KB Output is correct
28 Correct 5 ms 4956 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 372 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 19 ms 15964 KB Output is correct
11 Correct 8 ms 8284 KB Output is correct
12 Correct 4 ms 1884 KB Output is correct
13 Correct 5 ms 4444 KB Output is correct
14 Correct 8 ms 7516 KB Output is correct
15 Correct 8 ms 7272 KB Output is correct
16 Correct 8 ms 8028 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 4 ms 3420 KB Output is correct
22 Correct 9 ms 8280 KB Output is correct
23 Correct 10 ms 8284 KB Output is correct
24 Correct 2 ms 1372 KB Output is correct
25 Correct 2 ms 1400 KB Output is correct
26 Correct 2 ms 1372 KB Output is correct
27 Correct 1 ms 1372 KB Output is correct
28 Correct 5 ms 4956 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 4 ms 1372 KB Output is correct
38 Correct 75 ms 16812 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
42 Halted 0 ms 0 KB -