Submission #157626

#TimeUsernameProblemLanguageResultExecution timeMemory
157626gemini_manK blocks (IZhO14_blocks)C++11
0 / 100
4 ms504 KiB
#include <bits/stdc++.h> #define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i)) #define down(i,b,a) for(int (i) = (b);i>=(a);--i) #define debug(x) cerr << (x) << '\n'; #define bits(x,i) ((x >> i) & 1) using namespace std; const int N = 100005; const int K = 105; const long long INF = 1e18; int n,k; long long dp[N][K]; int a[N]; int lf[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); freopen("block.in","r", stdin); freopen("block.out","w", stdout); cin >> n >> k; up(i,1,n) cin >> a[i]; int curMax = 0; up(i,0,n) up(j,0,k) dp[i][j] = INF; up(i,1,n){ curMax = max(curMax, a[i]); dp[i][1] = curMax; } int s = 0; up(i,1,k){ s += a[i]; dp[i][i] = s; } vector<int> sk; up(i,1,n){ while (!sk.empty()) { if (a[sk.back()] < a[i]) sk.pop_back(); else break; } if (!sk.empty()) lf[i] = sk.back() + 1; else lf[i] = 1; sk.push_back(i); } for( int i = 2;i <= n;++i){ for(int j = 2; j < min(i,k+1) ;++j){ dp[i][j] = min(dp[max(lf[i], j-1)][j-1] + a[i], dp[lf[i]-1][j]); } } cout << dp[n][k]; }

Compilation message (stderr)

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