Submission #1232337

#TimeUsernameProblemLanguageResultExecution timeMemory
1232337QuocSenseiK blocks (IZhO14_blocks)C++20
100 / 100
318 ms88620 KiB
#include <bits/stdc++.h> #define ll long long #define el cout << '\n' #define ii pair<ll, ll> #define fi first #define se second using namespace std; const int maxn = 1e5; const int maxk = 1e2; const ll INF = 1e18; int n, k; ll a[maxn + 10], dp[maxn + 10][maxk + 10]; vector<ii> st; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("KBLOCK.INP", "r")) { freopen("KBLOCK.INP", "r", stdin); freopen("KBLOCK.OUT", "w", stdout); } cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; a[0] = INF; for (int j = 0; j <= k; j++) for (int i = 0; i <= n; i++) dp[i][j] = INF; dp[0][0] = 0; for (int j = 1; j <= k; j++) { st.clear(); st.push_back({0, dp[0][j - 1]}); for (int i = 1; i <= n; i++) { ll min_dp = dp[i - 1][j - 1]; while (a[st.back().fi] < a[i]) { min_dp = min(min_dp, st.back().se); st.pop_back(); } dp[i][j] = min(dp[st.back().fi][j], min_dp + a[i]); min_dp = min(min_dp, dp[i][j - 1]); st.push_back({i, min_dp}); } } // for (int j = 1; j <= k; j++) // { // for (int i = 1; i <= n; i++) // cout << dp[i][j] << ' '; // el; // } cout << dp[n][k]; }

Compilation message (stderr)

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