답안 #857731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
857731 2023-10-06T17:35:40 Z vgtcross Uplifting Excursion (BOI22_vault) C++17
40 / 100
4578 ms 9820 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int N = 1100000;
int dp[N], nx[N];
ll dp2[N], nx2[N];

void solve() {
    int m;
    ll x;
    cin >> m >> x;
    vector<ll> a(2*m+1);
    ll maxa = 0;
    for (ll &i : a) {
        cin >> i;
        maxa = max(maxa, i);
    }
    
    if (maxa <= 100) {
        ll mins = 0, maxs = 0;
        vector<pii> v;
        for (int i = -m; i <= m; ++i) {
            int f = a[i+m];
            
            if (i < 0) mins += f * i;
            else maxs += f * i;
            
            int z = 1;
            while (f > z) {
                v.push_back({z * i, z});
                f -= z;
                z *= 2;
            }
            if (f > 0) v.push_back({f * i, f});
        }
        
        memset(dp, 0xc0, sizeof dp);
        memset(nx, 0xc0, sizeof nx);
        dp[0] = nx[0] = 0;
        for (pii p : v) {
            for (int i = -550000; i <= 550000; ++i) {
                int j = i + p.first;
                if (-550000 <= j && j <= 550000) nx[(j + N) % N] = max(nx[(j + N) % N], dp[(i + N) % N] + p.second);
            }
            copy(nx, nx+N, dp);
        }
        
        if (x < mins || x > maxs) cout << "impossible\n";
        else cout << (dp[(x + N) % N] < 0 ? "impossible" : to_string(dp[(x + N) % N])) << '\n';
    } else {
        ll maxs = 0;
        vector<pii> v[m+1];
        for (int i = 1; i <= m; ++i) {
            ll f = a[i+m];

            maxs += f * i;

            f = min(f, (ll) m-1);

            int z = 1;
            while (f > z) {
                v[i].push_back({z * i, z});
                f -= z;
                z *= 2;
            }
            if (f > 0) v[i].push_back({f * i, f});
        }

        ll ans = -1;
        ll ofsi = 0;
        ll ofsa = 0;
        for (int k = 1; k <= m; ++k) {
            memset(dp2, 0xc0, 77000 * sizeof(ll));
            memset(nx2, 0xc0, 77000 * sizeof(ll));
            dp2[0] = nx2[0] = 0;
            for (int b = 1; b <= m; ++b) if (b != k) {
                for (pii p : v[b]) {
                    for (int i = 0; i <= 70000; ++i) {
                        int j = i + p.first;
                        if (j <= 70000) nx2[j] = max(nx2[j], dp2[i] + p.second);
                    }
                    copy(nx2, nx2+77000, dp2);
                }
            }

            for (int i = 0; i <= 70000; ++i) {
                if (i + ofsi > x) break;
                if ((x - i - ofsi) % k == 0 && (x - i - ofsi) / k <= a[k+m]) {
                    //cout << k << ' ' << i << ": " << ofsi << ' ' << dp2[i] << ' ' << (x - i - ofsi) / k << '\n';
                    ans = max(ans, ofsa + dp2[i] + (x - i - ofsi) / k);
                }
            }

            ofsi += max(0ll, a[k+m] - m + 1) * k;
            ofsa += max(0ll, a[k+m] - m + 1);
        }

        cout << (ans == -1 ? "impossible" : to_string(ans + a[m])) << '\n';
    }
}

int main() {
    cin.tie(0) -> sync_with_stdio(0);
    
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 9560 KB Output is correct
2 Correct 20 ms 9564 KB Output is correct
3 Correct 9 ms 9564 KB Output is correct
4 Correct 83 ms 9676 KB Output is correct
5 Correct 1295 ms 9688 KB Output is correct
6 Correct 1356 ms 9812 KB Output is correct
7 Correct 573 ms 9680 KB Output is correct
8 Correct 1298 ms 9684 KB Output is correct
9 Correct 1618 ms 9692 KB Output is correct
10 Correct 56 ms 9564 KB Output is correct
11 Correct 51 ms 9676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 9560 KB Output is correct
2 Correct 20 ms 9564 KB Output is correct
3 Correct 9 ms 9564 KB Output is correct
4 Correct 83 ms 9676 KB Output is correct
5 Correct 1295 ms 9688 KB Output is correct
6 Correct 1356 ms 9812 KB Output is correct
7 Correct 573 ms 9680 KB Output is correct
8 Correct 1298 ms 9684 KB Output is correct
9 Correct 1618 ms 9692 KB Output is correct
10 Correct 56 ms 9564 KB Output is correct
11 Correct 51 ms 9676 KB Output is correct
12 Correct 25 ms 9564 KB Output is correct
13 Correct 21 ms 9820 KB Output is correct
14 Correct 11 ms 9564 KB Output is correct
15 Correct 84 ms 9564 KB Output is correct
16 Correct 1304 ms 9684 KB Output is correct
17 Correct 1345 ms 9680 KB Output is correct
18 Correct 593 ms 9572 KB Output is correct
19 Correct 1302 ms 9812 KB Output is correct
20 Correct 1619 ms 9692 KB Output is correct
21 Correct 51 ms 9564 KB Output is correct
22 Correct 47 ms 9560 KB Output is correct
23 Correct 3138 ms 9704 KB Output is correct
24 Correct 3118 ms 9704 KB Output is correct
25 Correct 1188 ms 9560 KB Output is correct
26 Correct 3759 ms 9708 KB Output is correct
27 Correct 3841 ms 9712 KB Output is correct
28 Correct 55 ms 9564 KB Output is correct
29 Correct 71 ms 9680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 9564 KB Output is correct
2 Correct 324 ms 4716 KB Output is correct
3 Correct 108 ms 4716 KB Output is correct
4 Correct 334 ms 4944 KB Output is correct
5 Correct 374 ms 4700 KB Output is correct
6 Correct 293 ms 4700 KB Output is correct
7 Correct 24 ms 4700 KB Output is correct
8 Correct 33 ms 4700 KB Output is correct
9 Correct 171 ms 4696 KB Output is correct
10 Correct 231 ms 4724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 9564 KB Output is correct
2 Correct 324 ms 4716 KB Output is correct
3 Correct 108 ms 4716 KB Output is correct
4 Correct 334 ms 4944 KB Output is correct
5 Correct 374 ms 4700 KB Output is correct
6 Correct 293 ms 4700 KB Output is correct
7 Correct 24 ms 4700 KB Output is correct
8 Correct 33 ms 4700 KB Output is correct
9 Correct 171 ms 4696 KB Output is correct
10 Correct 231 ms 4724 KB Output is correct
11 Correct 28 ms 9812 KB Output is correct
12 Correct 20 ms 9564 KB Output is correct
13 Correct 10 ms 9560 KB Output is correct
14 Correct 82 ms 9564 KB Output is correct
15 Correct 318 ms 4696 KB Output is correct
16 Correct 113 ms 4716 KB Output is correct
17 Correct 330 ms 4724 KB Output is correct
18 Correct 358 ms 4944 KB Output is correct
19 Correct 286 ms 4700 KB Output is correct
20 Correct 24 ms 4696 KB Output is correct
21 Correct 33 ms 4700 KB Output is correct
22 Correct 174 ms 4728 KB Output is correct
23 Correct 247 ms 4700 KB Output is correct
24 Incorrect 304 ms 4700 KB Output isn't correct
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 9564 KB Output is correct
2 Correct 324 ms 4716 KB Output is correct
3 Correct 108 ms 4716 KB Output is correct
4 Correct 334 ms 4944 KB Output is correct
5 Correct 374 ms 4700 KB Output is correct
6 Correct 293 ms 4700 KB Output is correct
7 Correct 24 ms 4700 KB Output is correct
8 Correct 33 ms 4700 KB Output is correct
9 Correct 171 ms 4696 KB Output is correct
10 Correct 231 ms 4724 KB Output is correct
11 Correct 82 ms 9684 KB Output is correct
12 Correct 337 ms 4700 KB Output is correct
13 Correct 111 ms 4952 KB Output is correct
14 Correct 334 ms 4700 KB Output is correct
15 Correct 353 ms 4576 KB Output is correct
16 Correct 287 ms 4720 KB Output is correct
17 Correct 24 ms 4700 KB Output is correct
18 Correct 32 ms 4700 KB Output is correct
19 Correct 168 ms 4696 KB Output is correct
20 Correct 239 ms 4944 KB Output is correct
21 Correct 47 ms 9820 KB Output is correct
22 Correct 49 ms 9680 KB Output is correct
23 Correct 1027 ms 4724 KB Output is correct
24 Correct 479 ms 4728 KB Output is correct
25 Correct 1006 ms 4728 KB Output is correct
26 Correct 1202 ms 4728 KB Output is correct
27 Correct 1078 ms 4724 KB Output is correct
28 Correct 793 ms 4696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 9560 KB Output is correct
2 Correct 20 ms 9564 KB Output is correct
3 Correct 9 ms 9564 KB Output is correct
4 Correct 83 ms 9676 KB Output is correct
5 Correct 1295 ms 9688 KB Output is correct
6 Correct 1356 ms 9812 KB Output is correct
7 Correct 573 ms 9680 KB Output is correct
8 Correct 1298 ms 9684 KB Output is correct
9 Correct 1618 ms 9692 KB Output is correct
10 Correct 56 ms 9564 KB Output is correct
11 Correct 51 ms 9676 KB Output is correct
12 Correct 81 ms 9564 KB Output is correct
13 Correct 324 ms 4716 KB Output is correct
14 Correct 108 ms 4716 KB Output is correct
15 Correct 334 ms 4944 KB Output is correct
16 Correct 374 ms 4700 KB Output is correct
17 Correct 293 ms 4700 KB Output is correct
18 Correct 24 ms 4700 KB Output is correct
19 Correct 33 ms 4700 KB Output is correct
20 Correct 171 ms 4696 KB Output is correct
21 Correct 231 ms 4724 KB Output is correct
22 Correct 28 ms 9812 KB Output is correct
23 Correct 20 ms 9564 KB Output is correct
24 Correct 10 ms 9560 KB Output is correct
25 Correct 82 ms 9564 KB Output is correct
26 Correct 318 ms 4696 KB Output is correct
27 Correct 113 ms 4716 KB Output is correct
28 Correct 330 ms 4724 KB Output is correct
29 Correct 358 ms 4944 KB Output is correct
30 Correct 286 ms 4700 KB Output is correct
31 Correct 24 ms 4696 KB Output is correct
32 Correct 33 ms 4700 KB Output is correct
33 Correct 174 ms 4728 KB Output is correct
34 Correct 247 ms 4700 KB Output is correct
35 Incorrect 304 ms 4700 KB Output isn't correct
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 9564 KB Output is correct
2 Correct 324 ms 4716 KB Output is correct
3 Correct 108 ms 4716 KB Output is correct
4 Correct 334 ms 4944 KB Output is correct
5 Correct 374 ms 4700 KB Output is correct
6 Correct 293 ms 4700 KB Output is correct
7 Correct 24 ms 4700 KB Output is correct
8 Correct 33 ms 4700 KB Output is correct
9 Correct 171 ms 4696 KB Output is correct
10 Correct 231 ms 4724 KB Output is correct
11 Correct 82 ms 9684 KB Output is correct
12 Correct 337 ms 4700 KB Output is correct
13 Correct 111 ms 4952 KB Output is correct
14 Correct 334 ms 4700 KB Output is correct
15 Correct 353 ms 4576 KB Output is correct
16 Correct 287 ms 4720 KB Output is correct
17 Correct 24 ms 4700 KB Output is correct
18 Correct 32 ms 4700 KB Output is correct
19 Correct 168 ms 4696 KB Output is correct
20 Correct 239 ms 4944 KB Output is correct
21 Correct 47 ms 9820 KB Output is correct
22 Correct 49 ms 9680 KB Output is correct
23 Correct 1027 ms 4724 KB Output is correct
24 Correct 479 ms 4728 KB Output is correct
25 Correct 1006 ms 4728 KB Output is correct
26 Correct 1202 ms 4728 KB Output is correct
27 Correct 1078 ms 4724 KB Output is correct
28 Correct 793 ms 4696 KB Output is correct
29 Correct 81 ms 9676 KB Output is correct
30 Correct 318 ms 4720 KB Output is correct
31 Correct 110 ms 4944 KB Output is correct
32 Correct 329 ms 4724 KB Output is correct
33 Correct 358 ms 4724 KB Output is correct
34 Correct 287 ms 4724 KB Output is correct
35 Correct 24 ms 4700 KB Output is correct
36 Correct 33 ms 4696 KB Output is correct
37 Correct 172 ms 4716 KB Output is correct
38 Correct 247 ms 4696 KB Output is correct
39 Correct 46 ms 9560 KB Output is correct
40 Correct 47 ms 9564 KB Output is correct
41 Correct 1000 ms 4724 KB Output is correct
42 Correct 499 ms 4720 KB Output is correct
43 Correct 998 ms 4720 KB Output is correct
44 Correct 1154 ms 4724 KB Output is correct
45 Correct 1053 ms 4740 KB Output is correct
46 Correct 802 ms 4724 KB Output is correct
47 Correct 55 ms 9564 KB Output is correct
48 Correct 74 ms 9560 KB Output is correct
49 Incorrect 4578 ms 4728 KB Output isn't correct
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 9560 KB Output is correct
2 Correct 20 ms 9564 KB Output is correct
3 Correct 9 ms 9564 KB Output is correct
4 Correct 83 ms 9676 KB Output is correct
5 Correct 1295 ms 9688 KB Output is correct
6 Correct 1356 ms 9812 KB Output is correct
7 Correct 573 ms 9680 KB Output is correct
8 Correct 1298 ms 9684 KB Output is correct
9 Correct 1618 ms 9692 KB Output is correct
10 Correct 56 ms 9564 KB Output is correct
11 Correct 51 ms 9676 KB Output is correct
12 Correct 25 ms 9564 KB Output is correct
13 Correct 21 ms 9820 KB Output is correct
14 Correct 11 ms 9564 KB Output is correct
15 Correct 84 ms 9564 KB Output is correct
16 Correct 1304 ms 9684 KB Output is correct
17 Correct 1345 ms 9680 KB Output is correct
18 Correct 593 ms 9572 KB Output is correct
19 Correct 1302 ms 9812 KB Output is correct
20 Correct 1619 ms 9692 KB Output is correct
21 Correct 51 ms 9564 KB Output is correct
22 Correct 47 ms 9560 KB Output is correct
23 Correct 3138 ms 9704 KB Output is correct
24 Correct 3118 ms 9704 KB Output is correct
25 Correct 1188 ms 9560 KB Output is correct
26 Correct 3759 ms 9708 KB Output is correct
27 Correct 3841 ms 9712 KB Output is correct
28 Correct 55 ms 9564 KB Output is correct
29 Correct 71 ms 9680 KB Output is correct
30 Correct 81 ms 9564 KB Output is correct
31 Correct 324 ms 4716 KB Output is correct
32 Correct 108 ms 4716 KB Output is correct
33 Correct 334 ms 4944 KB Output is correct
34 Correct 374 ms 4700 KB Output is correct
35 Correct 293 ms 4700 KB Output is correct
36 Correct 24 ms 4700 KB Output is correct
37 Correct 33 ms 4700 KB Output is correct
38 Correct 171 ms 4696 KB Output is correct
39 Correct 231 ms 4724 KB Output is correct
40 Correct 28 ms 9812 KB Output is correct
41 Correct 20 ms 9564 KB Output is correct
42 Correct 10 ms 9560 KB Output is correct
43 Correct 82 ms 9564 KB Output is correct
44 Correct 318 ms 4696 KB Output is correct
45 Correct 113 ms 4716 KB Output is correct
46 Correct 330 ms 4724 KB Output is correct
47 Correct 358 ms 4944 KB Output is correct
48 Correct 286 ms 4700 KB Output is correct
49 Correct 24 ms 4696 KB Output is correct
50 Correct 33 ms 4700 KB Output is correct
51 Correct 174 ms 4728 KB Output is correct
52 Correct 247 ms 4700 KB Output is correct
53 Incorrect 304 ms 4700 KB Output isn't correct
54 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 9564 KB Output is correct
2 Correct 324 ms 4716 KB Output is correct
3 Correct 108 ms 4716 KB Output is correct
4 Correct 334 ms 4944 KB Output is correct
5 Correct 374 ms 4700 KB Output is correct
6 Correct 293 ms 4700 KB Output is correct
7 Correct 24 ms 4700 KB Output is correct
8 Correct 33 ms 4700 KB Output is correct
9 Correct 171 ms 4696 KB Output is correct
10 Correct 231 ms 4724 KB Output is correct
11 Correct 82 ms 9684 KB Output is correct
12 Correct 337 ms 4700 KB Output is correct
13 Correct 111 ms 4952 KB Output is correct
14 Correct 334 ms 4700 KB Output is correct
15 Correct 353 ms 4576 KB Output is correct
16 Correct 287 ms 4720 KB Output is correct
17 Correct 24 ms 4700 KB Output is correct
18 Correct 32 ms 4700 KB Output is correct
19 Correct 168 ms 4696 KB Output is correct
20 Correct 239 ms 4944 KB Output is correct
21 Correct 47 ms 9820 KB Output is correct
22 Correct 49 ms 9680 KB Output is correct
23 Correct 1027 ms 4724 KB Output is correct
24 Correct 479 ms 4728 KB Output is correct
25 Correct 1006 ms 4728 KB Output is correct
26 Correct 1202 ms 4728 KB Output is correct
27 Correct 1078 ms 4724 KB Output is correct
28 Correct 793 ms 4696 KB Output is correct
29 Correct 81 ms 9676 KB Output is correct
30 Correct 318 ms 4720 KB Output is correct
31 Correct 110 ms 4944 KB Output is correct
32 Correct 329 ms 4724 KB Output is correct
33 Correct 358 ms 4724 KB Output is correct
34 Correct 287 ms 4724 KB Output is correct
35 Correct 24 ms 4700 KB Output is correct
36 Correct 33 ms 4696 KB Output is correct
37 Correct 172 ms 4716 KB Output is correct
38 Correct 247 ms 4696 KB Output is correct
39 Correct 46 ms 9560 KB Output is correct
40 Correct 47 ms 9564 KB Output is correct
41 Correct 1000 ms 4724 KB Output is correct
42 Correct 499 ms 4720 KB Output is correct
43 Correct 998 ms 4720 KB Output is correct
44 Correct 1154 ms 4724 KB Output is correct
45 Correct 1053 ms 4740 KB Output is correct
46 Correct 802 ms 4724 KB Output is correct
47 Correct 55 ms 9564 KB Output is correct
48 Correct 74 ms 9560 KB Output is correct
49 Incorrect 4578 ms 4728 KB Output isn't correct
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 9560 KB Output is correct
2 Correct 20 ms 9564 KB Output is correct
3 Correct 9 ms 9564 KB Output is correct
4 Correct 83 ms 9676 KB Output is correct
5 Correct 1295 ms 9688 KB Output is correct
6 Correct 1356 ms 9812 KB Output is correct
7 Correct 573 ms 9680 KB Output is correct
8 Correct 1298 ms 9684 KB Output is correct
9 Correct 1618 ms 9692 KB Output is correct
10 Correct 56 ms 9564 KB Output is correct
11 Correct 51 ms 9676 KB Output is correct
12 Correct 25 ms 9564 KB Output is correct
13 Correct 21 ms 9820 KB Output is correct
14 Correct 11 ms 9564 KB Output is correct
15 Correct 84 ms 9564 KB Output is correct
16 Correct 1304 ms 9684 KB Output is correct
17 Correct 1345 ms 9680 KB Output is correct
18 Correct 593 ms 9572 KB Output is correct
19 Correct 1302 ms 9812 KB Output is correct
20 Correct 1619 ms 9692 KB Output is correct
21 Correct 51 ms 9564 KB Output is correct
22 Correct 47 ms 9560 KB Output is correct
23 Correct 3138 ms 9704 KB Output is correct
24 Correct 3118 ms 9704 KB Output is correct
25 Correct 1188 ms 9560 KB Output is correct
26 Correct 3759 ms 9708 KB Output is correct
27 Correct 3841 ms 9712 KB Output is correct
28 Correct 55 ms 9564 KB Output is correct
29 Correct 71 ms 9680 KB Output is correct
30 Correct 81 ms 9564 KB Output is correct
31 Correct 324 ms 4716 KB Output is correct
32 Correct 108 ms 4716 KB Output is correct
33 Correct 334 ms 4944 KB Output is correct
34 Correct 374 ms 4700 KB Output is correct
35 Correct 293 ms 4700 KB Output is correct
36 Correct 24 ms 4700 KB Output is correct
37 Correct 33 ms 4700 KB Output is correct
38 Correct 171 ms 4696 KB Output is correct
39 Correct 231 ms 4724 KB Output is correct
40 Correct 28 ms 9812 KB Output is correct
41 Correct 20 ms 9564 KB Output is correct
42 Correct 10 ms 9560 KB Output is correct
43 Correct 82 ms 9564 KB Output is correct
44 Correct 318 ms 4696 KB Output is correct
45 Correct 113 ms 4716 KB Output is correct
46 Correct 330 ms 4724 KB Output is correct
47 Correct 358 ms 4944 KB Output is correct
48 Correct 286 ms 4700 KB Output is correct
49 Correct 24 ms 4696 KB Output is correct
50 Correct 33 ms 4700 KB Output is correct
51 Correct 174 ms 4728 KB Output is correct
52 Correct 247 ms 4700 KB Output is correct
53 Incorrect 304 ms 4700 KB Output isn't correct
54 Halted 0 ms 0 KB -