Submission #877997

# Submission time Handle Problem Language Result Execution time Memory
877997 2023-11-24T01:57:00 Z noiaint Holding (COCI20_holding) C++17
110 / 110
67 ms 16908 KB
#include <bits/stdc++.h>

#define int long long

using namespace std;

const int N = 105;
const long long ooo = 1e18;

int mini(int &x, int y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}

int n, l, r, k;
int a[N];
int f[2][N][10005];

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

    cin >> n >> l >> r >> k;
    for (int i = 1; i <= n; ++i) cin >> a[i];

    memset(f, 0x3f, sizeof f);
    f[0][0][0] = 0;
    for(int i = 1; i <= n; ++i) {
        for(int j = 0; j <= r - l + 1; ++j) {
            int pos = l + j - 1;
            for(int cost = 0; cost <= k; ++cost) {
                f[i & 1][j][cost] = f[i & 1 ^ 1][j][cost];
                if(abs(pos - i) > cost || j == 0) continue;
                mini(f[i & 1][j][cost], f[i & 1 ^ 1][j - 1][cost - abs(pos - i)] + a[i]); 
            }
        }
    }
    int res = ooo;
    for(int i = 0; i <= k; ++i) mini(res, f[n & 1][r - l + 1][i]);
    cout << res;


    return 0;
}

/*

*/

Compilation message

holding.cpp: In function 'int main()':
holding.cpp:35:41: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   35 |                 f[i & 1][j][cost] = f[i & 1 ^ 1][j][cost];
      |                                       ~~^~~
holding.cpp:37:45: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   37 |                 mini(f[i & 1][j][cost], f[i & 1 ^ 1][j - 1][cost - abs(pos - i)] + a[i]);
      |                                           ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16732 KB Output is correct
2 Correct 3 ms 16732 KB Output is correct
3 Correct 3 ms 16732 KB Output is correct
4 Correct 4 ms 16732 KB Output is correct
5 Correct 3 ms 16728 KB Output is correct
6 Correct 3 ms 16732 KB Output is correct
7 Correct 4 ms 16732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16732 KB Output is correct
2 Correct 3 ms 16732 KB Output is correct
3 Correct 3 ms 16732 KB Output is correct
4 Correct 4 ms 16732 KB Output is correct
5 Correct 3 ms 16728 KB Output is correct
6 Correct 3 ms 16732 KB Output is correct
7 Correct 4 ms 16732 KB Output is correct
8 Correct 3 ms 16732 KB Output is correct
9 Correct 3 ms 16732 KB Output is correct
10 Correct 3 ms 16732 KB Output is correct
11 Correct 3 ms 16732 KB Output is correct
12 Correct 3 ms 16732 KB Output is correct
13 Correct 19 ms 16908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16732 KB Output is correct
2 Correct 3 ms 16732 KB Output is correct
3 Correct 3 ms 16732 KB Output is correct
4 Correct 4 ms 16732 KB Output is correct
5 Correct 3 ms 16728 KB Output is correct
6 Correct 3 ms 16732 KB Output is correct
7 Correct 4 ms 16732 KB Output is correct
8 Correct 3 ms 16732 KB Output is correct
9 Correct 3 ms 16732 KB Output is correct
10 Correct 3 ms 16732 KB Output is correct
11 Correct 3 ms 16732 KB Output is correct
12 Correct 3 ms 16732 KB Output is correct
13 Correct 19 ms 16908 KB Output is correct
14 Correct 3 ms 16732 KB Output is correct
15 Correct 3 ms 16732 KB Output is correct
16 Correct 3 ms 16732 KB Output is correct
17 Correct 3 ms 16732 KB Output is correct
18 Correct 3 ms 16732 KB Output is correct
19 Correct 19 ms 16732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16732 KB Output is correct
2 Correct 3 ms 16732 KB Output is correct
3 Correct 3 ms 16732 KB Output is correct
4 Correct 4 ms 16732 KB Output is correct
5 Correct 3 ms 16728 KB Output is correct
6 Correct 3 ms 16732 KB Output is correct
7 Correct 4 ms 16732 KB Output is correct
8 Correct 3 ms 16732 KB Output is correct
9 Correct 3 ms 16732 KB Output is correct
10 Correct 3 ms 16732 KB Output is correct
11 Correct 3 ms 16732 KB Output is correct
12 Correct 3 ms 16732 KB Output is correct
13 Correct 19 ms 16908 KB Output is correct
14 Correct 3 ms 16732 KB Output is correct
15 Correct 3 ms 16732 KB Output is correct
16 Correct 3 ms 16732 KB Output is correct
17 Correct 3 ms 16732 KB Output is correct
18 Correct 3 ms 16732 KB Output is correct
19 Correct 19 ms 16732 KB Output is correct
20 Correct 3 ms 16732 KB Output is correct
21 Correct 3 ms 16896 KB Output is correct
22 Correct 3 ms 16732 KB Output is correct
23 Correct 4 ms 16732 KB Output is correct
24 Correct 6 ms 16732 KB Output is correct
25 Correct 67 ms 16732 KB Output is correct