제출 #877997

#제출 시각아이디문제언어결과실행 시간메모리
877997noiaintHolding (COCI20_holding)C++17
110 / 110
67 ms16908 KiB
#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;
}

/*

*/

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...