답안 #943650

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
943650 2024-03-11T17:26:55 Z LucaIlie Uplifting Excursion (BOI22_vault) C++17
0 / 100
1838 ms 18340 KB
#include <bits/stdc++.h>

using namespace std;

struct object {
    int g, c;
    long long k;
};

const int MAX_M = 300;
const int MAX_S = MAX_M * MAX_M;
const int MIN_S = -MAX_S;
const long long INF = 1e18;
unordered_map<int, long long> taken, untaken;
unordered_map<int, long long> dpCrt, dpPrv;

int main() {
    int m, l;
    long long u = 0, t = 0;

    cin >> m >> l;
    for ( int i = -m; i <= m; i++ ) {
        cin >> untaken[i];
        u += untaken[i];
    }

    if ( l < 0 ) {
        for ( int i = 1; i <= m; i++ )
            swap( untaken[i], untaken[-i] );
    }

    long long s = 0;
    for ( int i = -m; i <= 0; i++ ) {
        long long x = untaken[i];
        s += i * x;
        taken[i] += x;
        untaken[i] -= x;
        t += x;
        u -= x;
    }
    for ( int i = 1; i <= m; i++ ) {
        long long x = min( untaken[i], (l - s) / i );
        s += i * x;
        taken[i] += x;
        untaken[i] -= x;
        t += x;
        u -= x;
    }

    if ( s + m < l ) {
        for ( int i = -m; i < 0; i++ ) {
            long long x = min( taken[i], (l - s) / (-i) );
            s -= i * x;
            taken[i] -= x;
            untaken[i] += x;
            t -= x;
            u += x;
        }
    }

    for ( int s = MIN_S; s <= MAX_S; s++ )
        dpCrt[s] = -INF;
    dpCrt[0] = 0;
    for ( int i = -m; i <= 0; i++ ) {
        swap( dpCrt, dpPrv );

        for ( int s = MIN_S; s <= MAX_S; s++ )
            dpCrt[s] = -INF;

        for ( int x = 0; x <= m && x <= untaken[i]; x++ ) {
            for ( int s = MIN_S; s - i * x <= MAX_S; s++ )
                dpCrt[s] = max( dpCrt[s], dpPrv[s - i * x] + x );
        }
        for ( int x = 0; x <= m && x <= taken[i]; x++ ) {
            for ( int s = MIN_S - i * x; s <= MAX_S; s++ )
                dpCrt[s] = max( dpCrt[s], dpPrv[s + i * x] - x );
        }
    }
    for ( int i = 1; i <= m; i++ ) {
        swap( dpCrt, dpPrv );

        for ( int s = MIN_S; s <= MAX_S; s++ )
            dpCrt[s] = -INF;

        for ( int x = 0; x <= m && x <= untaken[i]; x++ ) {
            for ( int s = MIN_S + i * x; s <= MAX_S; s++ )
                dpCrt[s] = max( dpCrt[s], dpPrv[s - i * x] + x );
        }
        for ( int x = 0; x <= m && x <= taken[i]; x++ ) {
            for ( int s = MIN_S; s + i * x <= MAX_S; s++ )
                dpCrt[s] = max( dpCrt[s], dpPrv[s + i * x] - x );
        }
    }

    if ( dpCrt[l - s] < 0 )
        cout << "impossible\n";
    else
        cout << t + dpCrt[l - s] << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 18308 KB Output is correct
2 Correct 181 ms 18324 KB Output is correct
3 Correct 83 ms 18192 KB Output is correct
4 Correct 719 ms 18084 KB Output is correct
5 Incorrect 1838 ms 18340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 18308 KB Output is correct
2 Correct 181 ms 18324 KB Output is correct
3 Correct 83 ms 18192 KB Output is correct
4 Correct 719 ms 18084 KB Output is correct
5 Incorrect 1838 ms 18340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 734 ms 18296 KB Output is correct
2 Incorrect 928 ms 18308 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 734 ms 18296 KB Output is correct
2 Incorrect 928 ms 18308 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 734 ms 18296 KB Output is correct
2 Incorrect 928 ms 18308 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 18308 KB Output is correct
2 Correct 181 ms 18324 KB Output is correct
3 Correct 83 ms 18192 KB Output is correct
4 Correct 719 ms 18084 KB Output is correct
5 Incorrect 1838 ms 18340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 734 ms 18296 KB Output is correct
2 Incorrect 928 ms 18308 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 18308 KB Output is correct
2 Correct 181 ms 18324 KB Output is correct
3 Correct 83 ms 18192 KB Output is correct
4 Correct 719 ms 18084 KB Output is correct
5 Incorrect 1838 ms 18340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 734 ms 18296 KB Output is correct
2 Incorrect 928 ms 18308 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 18308 KB Output is correct
2 Correct 181 ms 18324 KB Output is correct
3 Correct 83 ms 18192 KB Output is correct
4 Correct 719 ms 18084 KB Output is correct
5 Incorrect 1838 ms 18340 KB Output isn't correct
6 Halted 0 ms 0 KB -