제출 #1349600

#제출 시각아이디문제언어결과실행 시간메모리
1349600haru09Holding (COCI20_holding)C++20
110 / 110
51 ms8656 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define task "code"

const int ar = 1e2 + 5;
const ll mod = 1e9 + 7;
const int N = 1e4;
const int inf = 1e9;
int q, n = 0, m = 0, l, r, k;
pair<int, int> a[ar], b[ar];
int dp[ar][N + 5], f[ar][N + 5];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    cin >> q >> l >> r >> k;
    for (int i = 1; i <= q; i++)
    {
        int x;
        cin >> x;
        if (l <= i && i <= r) a[++n] = {x, i};
        else b[++m] = {x, i};
    }
    memset(dp, 0x3f, sizeof dp);
    memset(f, 0x3f, sizeof f);
    for (int i = 0; i <= m; i++) f[i][0] = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= m; j++)
        {
            for (int t = 0; t <= k; t++)
            {
                dp[j][t] = min(dp[j][t], f[j][t] + a[i].fi);
                if (j >= 1) dp[j][t] = min(dp[j][t], dp[j - 1][t]);
                if (abs(a[i].se - b[j].se) <= t && j >= 1)
                {
                    dp[j][t] = min(dp[j][t], f[j - 1][t - abs(a[i].se - b[j].se)] + b[j].fi);
                }
            }
        }
        for (int j = 0; j <= m; j++)
        {
            for (int t = 0; t <= k; t++)
            {
                //cout << i << ' ' << j << ' ' << t << ' ' << dp[j][t] << '\n';
                f[j][t] = dp[j][t];
                dp[j][t] = inf;
            }
        }
    }
    int ans = inf;
    for (int i = 0; i <= k; i++) ans = min(ans, f[m][i]);
    cout << ans;
}

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

holding.cpp: In function 'int main()':
holding.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...