Submission #1101528

#TimeUsernameProblemLanguageResultExecution timeMemory
1101528tuan19aK blocks (IZhO14_blocks)C++14
100 / 100
149 ms83456 KiB
#include <bits/stdc++.h> #define ll long long #define int long long #define el "\n" #define FILE "test1" #define fi first #define se second #define pb push_back #define pii pair<int,int> #define bit(mask,i) ((mask>>i) & 1) const int N=1e5+2; const ll oo=1e18; const int mod=1e9+7; const int base=31; const int dx[4]={0, 0, 1, -1}; const int dy[4]={1, -1, 0, 0}; using namespace std; int n,k,a[N],dp[N][102],l[N],rmq[N][25]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); if (fopen(FILE".inp","r")) { freopen(FILE".inp","r",stdin); freopen(FILE".out","w",stdout); } cin>>n>>k; for (int i=1;i<=n;i++) cin>>a[i]; memset(dp,0x3f,sizeof dp); dp[0][1]=0; for (int i=1;i<=n;i++) dp[i][1]=max(dp[i-1][1],a[i]); for (int i=2;i<=k;i++) { stack <pii> s; for (int j=i;j<=n;j++) { int minn=dp[j-1][i-1]; while (!s.empty() && a[j]>=a[s.top().se]) minn=min(minn,s.top().fi),s.pop(); int pos=0; if (!s.empty()) pos=s.top().se; dp[j][i]=min(dp[pos][i],minn+a[j]); s.push({minn,j}); } } cout<<dp[n][k]; } /** /\_/\ * (= ._.) * / >AC \>AC **/

Compilation message (stderr)

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