제출 #1124229

#제출 시각아이디문제언어결과실행 시간메모리
1124229pndhpndhHolding (COCI20_holding)C++20
110 / 110
42 ms52040 KiB
#include<bits/stdc++.h> #define int long long #define pb push_back #define task "task" using namespace std; const int inf = 1e18; const int mx = 2e5 + 5; int n, l , r, k; int dpl[105][105][2505], dpr[105][105][2505]; int a[mx]; int pref[mx]; void read(){ cin >> n >> l >> r >> k; for (int i = 1; i <= n; i++){ cin >> a[i]; pref[i] = pref[i - 1] + a[i]; } k = min(k, n * n / 4); } void solve(){ // for (int i = l; i <= r; i++){ // for (int j = 0; j < l; j++){ // for (int c = 0; c <= 100; c++){ // dpl[i][j][c] = inf; // } // } // } for (int i = l; i <= r; i++){ for (int c = 0; c <= k; c++){ dpl[i][0][c] = pref[i] - pref[l - 1]; } for (int j = 1; j < l; j++){ for (int c = 0; c <= k; c++){ int cost = abs(i - j); dpl[i][j][c] = min(dpl[i - 1][j][c] + a[i], dpl[i][j - 1][c]); if (c >= cost){ dpl[i][j][c] = min(dpl[i][j][c], dpl[i - 1][j - 1][c - cost] + a[j]); } // cout << i << " " << j << " " << c << " " << dpl[i][j][c] << " " << dpl[i][j - 1][c] << " " << dpl[i - 1][j - 1][c - cost] << '\n'; } } } // for (int i = r; i >= l; i--){ // for (int j = n + 1; j > r; j--){ // for (int c = 0; c <= 100; c++){ // dpr[i][j][c] = inf; // } // } // } for (int i = r; i >= l; i--){ for (int c = 0; c <= k; c++){ dpr[i][n + 1][c] = pref[r] - pref[i - 1]; } for (int j = n; j > r; j--){ for (int c = 0; c <= k; c++){ int cost = abs(i - j); dpr[i][j][c] = min(dpr[i + 1][j][c] + a[i], dpr[i][j + 1][c]); // cout << i << " " << j << " " << c << " " << dpr[i][j][c] << '\n'; if (c >= cost){ dpr[i][j][c] = min(dpr[i][j][c], dpr[i + 1][j + 1][c - cost] + a[j]); } } } } int ans = min(dpl[r][l - 1][k], dpr[l][r + 1][k]); for (int pos = l; pos < r; pos++){ for (int cl = 0; cl <= k; cl++){ ans = min(ans, dpl[pos][l - 1][cl] + dpr[pos + 1][r + 1][k - cl]); // cout << pos << " " << l - 1 << " " << r + 1 << " " << cl << " " << cr << " " << dpl[pos][l - 1][cl] << " " << dpr[pos + 1][r + 1][cr] << '\n'; } } cout << ans; } signed main(){ cin.tie(0)->sync_with_stdio(0); if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } read(); solve(); }

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

holding.cpp: In function 'int main()':
holding.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         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...