Submission #334037

#TimeUsernameProblemLanguageResultExecution timeMemory
334037ronnithHolding (COCI20_holding)C++14
110 / 110
318 ms20812 KiB
#include <bits/stdc++.h> typedef long long ll; #define v vector #define vl vector<ll> #define mk make_pair #define f first #define s second using namespace std; int main(){ ll n, l, r, K; scanf("%lld%lld%lld%lld", &n, &l, &r, &K); ll a[n]; for(int i = 0;i < n;i ++){ scanf("%lld", &a[i]); } // int ans = INT_MAX; // for(int bit = 0;bit < (1<<n);bit ++){ // if(__builtin_popcount(bit) == n - l + 1){ // int sm = 0; // int cost = 0; // int h = l; // for(int i = 0;i < n;i ++){ // if(!((1<<i)&bit))continue; // cost += h - (i + 1); // h ++; // sm += a[i]; // } // if(cost <= k){ // ans = min(ans, sm); // } // } // } // printf("%d\n", ans); ll ans = INT_MAX; v<v<vl>> dp1(2, v<vl>(r - l + 2, vl(K + 1, INT_MAX))); v<v<vl>> dp2(2, v<vl>(r - l + 2, vl(K + 1, INT_MAX))); int crr = 0; int prev = 1; for(int i = 0;i < n;i ++){ for(int j = 0;j < r - l + 2;j ++){ for(int k = 0;k <= K;k ++){ dp1[crr][j][k] = dp2[crr][j][k] = INT_MAX; if(j == 0){ dp2[crr][j][k] = 0; } else if(i == 0){ if(j == 1){ if(abs(l - i - 1) == k) dp1[crr][j][k] = a[i]; } else { dp1[crr][j][k] = INT_MAX; } } else { if(abs(j - 1 + l - i - 1) <= k){ dp1[crr][j][k] = a[i] + min(dp1[prev][j - 1][k - abs(j - 1 + l - i - 1)], dp2[prev][j - 1][k - abs(j - 1 + l - i - 1)]);// abs(j - 1 + l - i) } dp2[crr][j][k] = min(dp1[prev][j][k], dp2[prev][j][k]); } if(i == n - 1 and j == r - l + 1) ans = min(ans, min(dp1[crr][j][k], dp2[crr][j][k])); } } crr = 1 - crr; prev = 1 - prev; } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

holding.cpp: In function 'int main()':
holding.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |  scanf("%lld%lld%lld%lld", &n, &l, &r, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |   scanf("%lld", &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...