답안 #947240

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
947240 2024-03-15T18:28:29 Z tmarcinkevicius Uplifting Excursion (BOI22_vault) C++14
0 / 100
295 ms 524288 KB
#include <bits/stdc++.h>  
using namespace std;

#define int int64_t
typedef pair<int,int> pii;
typedef vector<int> vii;
#define MP make_pair
#define PB push_back
#define f first
#define s second
#define INF 2e18
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

int M, L;

int32_t main()
{
    fast_io();

    cin >> M >> L;
    vector<int> values;
    values.push_back(0);
    int offset = 0;
    int maxVal = 0;

    for (int val = -M; val <= M; val++)
    {
        int x;
        cin >> x;
        for (int i = 0; i < x; i++)
        {
            values.push_back(val);
            if (val > 0)
            {
                maxVal += val;
            }
            else
            {
                offset -= val;
            }
        }
    }

    if (L > maxVal)
    {
        cout << "impossible\n";
        return 0;
    }

    /*cout << "values: {";
    for (int i : values)
    {
        cout << i << " ";
    }
    cout << "}\n";*/

    offset *= 2;

    //cout << "L = " << L << ", offset = " << offset << ", maxVal = " << maxVal << '\n';
    //return 0;
    int sizeY = offset + maxVal;

    int dp[2][sizeY];

    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < sizeY; j++)
        {
            dp[i][j] = -INF;
        }
    }

    dp[0][offset] = 0;

    for (int i = 1; i < values.size(); i++)
    {
        for (int l = -offset; offset + l < sizeY; l++)
        {
            //cout << "realVal: " << l << '\n';
            int liek = i % 2;
            int prev = 1 - liek;
            dp[liek][offset + l] = dp[prev][offset + l];

            if (offset + l - values[i] >= 0 && offset + l - values[i] < sizeY)
            {
                dp[liek][offset + l] = max(dp[prev][offset + l], dp[prev][offset + l - values[i]] + 1);
            }
        }
    }

    /*for (int l = -L; l <= L; l++)
    {
        cout << setw(5) << l << " ";
    }
    cout << '\n';
    for (int i = 0; i < values.size(); i++)
    {
        for (int l = -L; l <= L; l++)
        {
            if (dp[i][offset + L] < -INF / 2)
            {
                cout << setw(5) << "-";
            }
            else
            {
                cout << setw(5) << dp[i][offset + L];
            }
            cout << " ";
        }
        cout << '\n';
    }*/

    int liek = (values.size() - 1) % 2;

    if (dp[liek][offset + L] <= 0)
    {
        cout << "impossible\n";
    }
    else
    {
        cout << dp[liek][offset + L] << '\n';
    }
    
}

Compilation message

vault.cpp: In function 'int32_t main()':
vault.cpp:77:23: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for (int i = 1; i < values.size(); i++)
      |                     ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 Runtime error 248 ms 3596 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Runtime error 248 ms 3596 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 295 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 295 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 295 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Runtime error 248 ms 3596 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 295 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Runtime error 248 ms 3596 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 295 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Runtime error 248 ms 3596 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -