Submission #708031

# Submission time Handle Problem Language Result Execution time Memory
708031 2023-03-10T20:10:55 Z Johann Uplifting Excursion (BOI22_vault) C++14
20 / 100
4122 ms 15516 KB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;
typedef vector<ll> vi;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

vi calcShifts(int a)
{
    vi ans;
    int i = 0;
    while ((1 << i) <= a)
    {
        a -= (1 << i);
        ans.push_back(i++);
    }
    while (i > 0)
        if ((1 << --i) <= a)
            ans.push_back(i), a -= (1 << i);
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll M, L;
    cin >> M >> L;
    vi A(2 * M + 1);
    for (int i = 0; i < sz(A); ++i)
        cin >> A[i];

    int an = accumulate(A.begin(), A.begin() + M, 0);
    int ap = accumulate(A.begin() + M + 1, A.begin() + 2 * M + 1, 0);

    int MAXSIZE = 2 * M * max(an, ap) + 2;

    vi dp(MAXSIZE, -1);
    ll center = MAXSIZE / 2;
    dp[center] = A[M];
    for (int foo = 0; foo < 2; ++foo)
    {
        reverse(all(A)), reverse(all(dp));
        for (ll m = 1; m <= M; ++m)
        {
            ll maxNum = A[m + M];
            vi shifts = calcShifts(maxNum);
            for (int i : shifts)
            {
                ll amount = (1 << i);
                ll d = amount * m;
                for (int j = sz(dp) - 1; j >= d; --j)
                    dp[j] = max(dp[j], (dp[j - d] != -1) ? dp[j - d] + amount : -1);
            }
        }
    }

    ll ans = -1;
    if (0 <= center + L && center + L < sz(dp))
        ans = dp[center + L];
    if (ans == -1)
        cout << "impossible\n";
    else
        cout << ans << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 77 ms 1236 KB Output is correct
6 Correct 92 ms 1364 KB Output is correct
7 Correct 18 ms 724 KB Output is correct
8 Correct 76 ms 1236 KB Output is correct
9 Correct 204 ms 2132 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 77 ms 1236 KB Output is correct
6 Correct 92 ms 1364 KB Output is correct
7 Correct 18 ms 724 KB Output is correct
8 Correct 76 ms 1236 KB Output is correct
9 Correct 204 ms 2132 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 78 ms 1236 KB Output is correct
17 Correct 113 ms 1364 KB Output is correct
18 Correct 18 ms 724 KB Output is correct
19 Correct 75 ms 1236 KB Output is correct
20 Correct 187 ms 2132 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1857 ms 8660 KB Output is correct
24 Correct 1825 ms 8176 KB Output is correct
25 Correct 213 ms 3156 KB Output is correct
26 Correct 4122 ms 15516 KB Output is correct
27 Correct 4011 ms 15444 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 77 ms 1236 KB Output is correct
6 Correct 92 ms 1364 KB Output is correct
7 Correct 18 ms 724 KB Output is correct
8 Correct 76 ms 1236 KB Output is correct
9 Correct 204 ms 2132 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Incorrect 1 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 77 ms 1236 KB Output is correct
6 Correct 92 ms 1364 KB Output is correct
7 Correct 18 ms 724 KB Output is correct
8 Correct 76 ms 1236 KB Output is correct
9 Correct 204 ms 2132 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 78 ms 1236 KB Output is correct
17 Correct 113 ms 1364 KB Output is correct
18 Correct 18 ms 724 KB Output is correct
19 Correct 75 ms 1236 KB Output is correct
20 Correct 187 ms 2132 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1857 ms 8660 KB Output is correct
24 Correct 1825 ms 8176 KB Output is correct
25 Correct 213 ms 3156 KB Output is correct
26 Correct 4122 ms 15516 KB Output is correct
27 Correct 4011 ms 15444 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Incorrect 1 ms 212 KB Output isn't correct
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 77 ms 1236 KB Output is correct
6 Correct 92 ms 1364 KB Output is correct
7 Correct 18 ms 724 KB Output is correct
8 Correct 76 ms 1236 KB Output is correct
9 Correct 204 ms 2132 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 78 ms 1236 KB Output is correct
17 Correct 113 ms 1364 KB Output is correct
18 Correct 18 ms 724 KB Output is correct
19 Correct 75 ms 1236 KB Output is correct
20 Correct 187 ms 2132 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1857 ms 8660 KB Output is correct
24 Correct 1825 ms 8176 KB Output is correct
25 Correct 213 ms 3156 KB Output is correct
26 Correct 4122 ms 15516 KB Output is correct
27 Correct 4011 ms 15444 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Incorrect 1 ms 212 KB Output isn't correct
32 Halted 0 ms 0 KB -