Submission #1022454

#TimeUsernameProblemLanguageResultExecution timeMemory
1022454lmToT27Holding (COCI20_holding)C++14
110 / 110
18 ms25148 KiB
#include <bits/stdc++.h> #define all(dataStructure) dataStructure.begin(),dataStructure.end() #define ll long long using namespace std; namespace std { template <typename T, int D> struct _vector : public vector <_vector <T, D - 1>> { static_assert(D >= 1, "Dimension must be positive!"); template <typename... Args> _vector(int n = 0, Args... args) : vector <_vector <T, D - 1>> (n, _vector <T, D - 1> (args...)) {} }; // _vector <int, 3> a(n, m, k);: int a[n][m][k]. // _vector <int, 3> a(n, m, k, x);: int a[n][m][k] initialized with x. template <typename T> struct _vector <T, 1> : public vector <T> { _vector(int n = 0, const T& val = T()) : vector <T> (n, val) {} }; } const int MAX = 1e2 + 2; const ll MOD[] = {1000000007, 998244353}; int dpL[102][102][2507]; int dpR[102][102][2507]; int n, K, a[102], l, r; int sum = 0; void Solve() { cin >> n >> l >> r >> K; K = min(K, n * n / 4); for (int i = 1; i <= n; i++) cin >> a[i]; sum = accumulate(a + l, a + r + 1, 0); for (int i = 1; i < l; i++) { for (int j = l; j <= r; j++) { for (int k = 0; k <= K; k++) { dpL[i][j][k] = max(dpL[i - 1][j][k], dpL[i][j - 1][k]); if (k >= j - i) dpL[i][j][k] = max(dpL[i][j][k], dpL[i - 1][j - 1][k - j + i] + a[j] - a[i]); } } } for (int i = n; i > r; i--) { for (int j = r; j >= l; j--) { for (int k = 0; k <= K; k++) { dpR[j][i][k] = max(dpR[j + 1][i][k], dpR[j][i + 1][k]); if (k >= i - j) dpR[j][i][k] = max(dpR[j][i][k], dpR[j + 1][i + 1][k - i + j] + a[j] - a[i]); } } } int res = max(dpL[l - 1][r][K], dpR[l][r + 1][K]); for (int i = l; i <= r; i++) { for (int k = 0; k <= K; k++) { res = max(res, dpL[l - 1][i][k] + dpR[i + 1][r + 1][K - k]); } } cout << sum - res; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); #define TASK "HOLDING" if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } /* int TEST = 1; cin >> TEST; while (TEST--) */ Solve(); cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n"; return 0; }

Compilation message (stderr)

holding.cpp: In function 'int32_t main()':
holding.cpp:65:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |                 freopen(TASK".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:66:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |                 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...