Submission #1077155

#TimeUsernameProblemLanguageResultExecution timeMemory
1077155duyhoanhoK blocks (IZhO14_blocks)C++17
100 / 100
210 ms82048 KiB
#include <bits/stdc++.h> #define task "" #define int long long #define forinc(i,a,b) for(int i=a;i<=b;i++) using namespace std; const int N=1e5+10; int n,a[N],dp[N][102],k; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); if (fopen ("blocks.in", "r")) { freopen ("blocks.in", "r", stdin); freopen ("blocks.out", "w", stdout); } cin>>n>>k; memset(dp,99,sizeof dp); int mx=0; forinc(i,1,n) { cin>>a[i]; mx=max(mx,a[i]); dp[i][1] = mx; } for(int j=2; j<=k; j++) { stack<int> st; for(int i=1; i<=n; i++) { while(st.size() && a[st.top()] <= a[i] ) { dp[i][j] = min(dp[i][j], dp[st.top()][j-1] + a[i]); dp[i][j] = min(dp[i][j],dp[st.top()][j] - a[st.top()] + a[i]); st.pop(); } if(st.size()) { dp[i][j] = min(dp[i][j], dp[st.top()][j-1] + a[i]); dp[i][j] = min(dp[i][j],dp[st.top()][j]); dp[i][j] = min(dp[i][j] , dp[st.top() - 1][j - 1] + a[st.top()]); } st.push(i); } } // forinc(i,1,n) // { // forinc(j,1,k) cout<<dp[i][j]<<" "; // cout<<"\n"; // } cout<<dp[n][k]; }

Compilation message (stderr)

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