Submission #1242851

#TimeUsernameProblemLanguageResultExecution timeMemory
1242851hainam2k9Holding (COCI20_holding)C++20
110 / 110
156 ms12508 KiB
#include <bits/stdc++.h> #define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0) #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout) #define ll long long #define ull unsigned long long #define i128 __int128 #define db long double #define sz(a) ((int)(a).size()) #define pb emplace_back #define pf emplace_front #define pob pop_back #define pof pop_front #define lb lower_bound #define ub upper_bound #define fi first #define se second #define ins emplace #define mp make_pair using namespace std; const int MOD = 1e9+7, MAXN = 1e5+5, offset = 100; const string NAME = ""; int n,l,r,k,a[105],dp[205][10005],nxtdp[205][10005],rs=1e9; inline void chmin(int& a, int b){ a=min(a,b); } int main() { tt; if(fopen((NAME + ".INP").c_str(), "r")) fo; cin >> n >> l >> r >> k; for(int i = 1; i<=n; ++i) cin >> a[i]; int sz=r-l+1; memset(nxtdp,0x3f,sizeof(nxtdp)); nxtdp[offset][0]=accumulate(a+l,a+r+1,0); for(int i = 0; i<n; ++i){ for(int j = -sz; j<=sz; ++j) for(int cost = 0; cost<=k; ++cost) dp[j+offset][cost]=nxtdp[j+offset][cost], nxtdp[j+offset][cost]=1e9; for(int j = -sz; j<=sz; ++j) for(int cost = 0; cost<=k; ++cost){ if(dp[j+offset][cost]>=1e9) continue; int newcost=cost+abs(j); if(newcost>k) continue; chmin(nxtdp[j+offset][newcost],dp[j+offset][cost]); if(j<sz&&(i+1<l||i+1>r)) chmin(nxtdp[j+1+offset][newcost],dp[j+offset][cost]+a[i+1]); if(j>-sz&&i+1>=l&&i+1<=r) chmin(nxtdp[j-1+offset][newcost],dp[j+offset][cost]-a[i+1]); } } for(int cost = 0; cost<=k; ++cost) rs=min(rs,nxtdp[offset][cost]); cout << rs; }

Compilation message (stderr)

holding.cpp: In function 'int main()':
holding.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:29:45: note: in expansion of macro 'fo'
   29 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
holding.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:29:45: note: in expansion of macro 'fo'
   29 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...