Submission #638331

#TimeUsernameProblemLanguageResultExecution timeMemory
638331nguyentunglamK blocks (IZhO14_blocks)C++14
0 / 100
1 ms408 KiB
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define forin(i, a, b) for(int i = a; i <= b; i++) #define forde(i, a, b) for(int i = a; i >= b; i--) #define forv(a, b) for(auto & a : b) #define fi first #define se second #define ii pair<int, int> #define endl "\n" using namespace std; const int N = 1e5 + 10; int a[N], dp[N][110]; stack<pair<int, int>> s[110]; int main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int n, k; cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) { for(int j = k; j >= 1; j--) { while (!s[j - 1].empty() && s[j - 1].top().fi <= a[i]) s[j - 1].pop(); dp[i][j] = dp[j - 1][j - 1] + a[i]; if (!s[j - 1].empty()) dp[i][j] = min(s[j - 1].top().se, dp[s[j - 1].top().fi][j - 1] + a[i]); s[j].push({i, dp[i][j]}); } } cout << dp[n][k]; }

Compilation message (stderr)

blocks.cpp: In function 'int main()':
blocks.cpp:18:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:19:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:22:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:23:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen (task".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...