Submission #671305

#TimeUsernameProblemLanguageResultExecution timeMemory
671305hct_2so1K개의 묶음 (IZhO14_blocks)C++17
0 / 100
17 ms41300 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int K = 105; const int INF = 0x3f3f3f3f; int a[N]; int L[N], minF[N]; int dp[K][N]; int n, k; int main() { freopen("blocks.in", "r", stdin); freopen("blocks.out", "w", stdout); cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; memset(dp, 0x3f, sizeof dp); dp[1][0] = 0; for (int i = 1; i <= n; ++i) dp[1][i] = max(dp[1][i - 1], a[i]); for (int i = 2; i <= k; ++i) { stack<pair<int, int> > S; for (int j = i; j <= n; ++j) { int minF = dp[i - 1][j - 1]; while (!S.empty() && a[S.top().second] <= a[j]) { minF = min(minF, S.top().first); //cout<<S.top().second<<' '<<S.top().first<<'\n'; S.pop(); } dp[i][j] = min(dp[i][S.empty() ? 0 : S.top().second], minF + a[j]); S.push(make_pair(minF, j)); } } cout << dp[k][n] << endl; return 0; }

Compilation message (stderr)

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