Submission #591007

# Submission time Handle Problem Language Result Execution time Memory
591007 2022-07-06T17:20:55 Z nguyen31hoang08minh2003 Holding (COCI20_holding) C++14
88 / 110
58 ms 118868 KB
#include <bits/stdc++.h>
#define fore(i, a, b) for (signed i = (a), i##_last = (b); i < i##_last; ++i)
#define fort(i, a, b) for (signed i = (a), i##_last = (b); i <= i##_last; ++i)
#define ford(i, a, b) for (signed i = (a), i##_last = (b); i >= i##_last; --i)
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using ld = long double;

template<class A, class B> bool maxi(A &a, const B &b) {return (a < b) ? (a = b, true):false;};
template<class A, class B> bool mini(A &a, const B &b) {return (a > b) ? (a = b, true):false;};

typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

const int maxN = 55, maxK = 10005, inf = 0x3f3f3f3f;

int n, l, r, k, a[maxN], dp[maxN][maxN][maxK];

int DP(int x, int y, int z) {
    if (x == l)
        return DP(r + 1, y, z);
    if (y > r)
        return 0;
    if (dp[x][y][z] < 0) {
        const int d = abs(x - y);
        dp[x][y][z] = inf;
        mini(dp[x][y][z], a[y] + DP(x, y + 1, z));
        if (x <= n) {
            mini(dp[x][y][z], DP(x + 1, y, z));
            if (d <= z)
                mini(dp[x][y][z], DP(x + 1, y + 1, z - d) + a[x]);
        }
    }
    return dp[x][y][z];
}

void subtask3() {
    memset(dp, -1, sizeof(dp));
    cout << DP(1, l, k) << '\n';
}

void subtask4() {
    cout << 0 << '\n';
}

void input() {
    cin >> n >> l >> r >> k;
    fort(i, 1, n)
        cin >> a[i];
}

int main() {
    #ifdef LOCAL
        freopen("input.INP", "r", stdin);
    #endif // LOCAL
    cin.tie(0) -> sync_with_stdio(0);
    cout.tie(0);
    input();
    if (n <= 50)
        subtask3();
    else
        subtask4();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 43 ms 118668 KB Output is correct
2 Correct 42 ms 118732 KB Output is correct
3 Correct 42 ms 118708 KB Output is correct
4 Correct 47 ms 118736 KB Output is correct
5 Correct 44 ms 118840 KB Output is correct
6 Correct 45 ms 118664 KB Output is correct
7 Correct 58 ms 118728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 118668 KB Output is correct
2 Correct 42 ms 118732 KB Output is correct
3 Correct 42 ms 118708 KB Output is correct
4 Correct 47 ms 118736 KB Output is correct
5 Correct 44 ms 118840 KB Output is correct
6 Correct 45 ms 118664 KB Output is correct
7 Correct 58 ms 118728 KB Output is correct
8 Correct 44 ms 118756 KB Output is correct
9 Correct 45 ms 118756 KB Output is correct
10 Correct 43 ms 118704 KB Output is correct
11 Correct 46 ms 118708 KB Output is correct
12 Correct 45 ms 118744 KB Output is correct
13 Correct 48 ms 118696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 118668 KB Output is correct
2 Correct 42 ms 118732 KB Output is correct
3 Correct 42 ms 118708 KB Output is correct
4 Correct 47 ms 118736 KB Output is correct
5 Correct 44 ms 118840 KB Output is correct
6 Correct 45 ms 118664 KB Output is correct
7 Correct 58 ms 118728 KB Output is correct
8 Correct 44 ms 118756 KB Output is correct
9 Correct 45 ms 118756 KB Output is correct
10 Correct 43 ms 118704 KB Output is correct
11 Correct 46 ms 118708 KB Output is correct
12 Correct 45 ms 118744 KB Output is correct
13 Correct 48 ms 118696 KB Output is correct
14 Correct 44 ms 118732 KB Output is correct
15 Correct 48 ms 118800 KB Output is correct
16 Correct 44 ms 118672 KB Output is correct
17 Correct 45 ms 118868 KB Output is correct
18 Correct 45 ms 118728 KB Output is correct
19 Correct 46 ms 118724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 118668 KB Output is correct
2 Correct 42 ms 118732 KB Output is correct
3 Correct 42 ms 118708 KB Output is correct
4 Correct 47 ms 118736 KB Output is correct
5 Correct 44 ms 118840 KB Output is correct
6 Correct 45 ms 118664 KB Output is correct
7 Correct 58 ms 118728 KB Output is correct
8 Correct 44 ms 118756 KB Output is correct
9 Correct 45 ms 118756 KB Output is correct
10 Correct 43 ms 118704 KB Output is correct
11 Correct 46 ms 118708 KB Output is correct
12 Correct 45 ms 118744 KB Output is correct
13 Correct 48 ms 118696 KB Output is correct
14 Correct 44 ms 118732 KB Output is correct
15 Correct 48 ms 118800 KB Output is correct
16 Correct 44 ms 118672 KB Output is correct
17 Correct 45 ms 118868 KB Output is correct
18 Correct 45 ms 118728 KB Output is correct
19 Correct 46 ms 118724 KB Output is correct
20 Runtime error 5 ms 468 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -