Submission #1039070

#TimeUsernameProblemLanguageResultExecution timeMemory
1039070ttviet2805K blocks (IZhO14_blocks)C++14
0 / 100
1 ms604 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define II pair <int, int> #define fi first #define se second #define all(S) S.begin(), S.end() const int INF = 1e15; const int N = 1e5 + 5; int n, a[N], K; void in() { cin >> n >> K; for(int i = 1; i <= n; i++) { cin >> a[i]; } vector <vector <int>> f(K + 1, vector <int> (n + 5, INF)); stack <II> st; f[0][0] = 0; a[0] = INF; for(int X = 1; X <= K; X++) { st.push({X - 1, f[X - 1][X - 1]}); for(int i = X; i <= n; i++) { int curMin = INF; while(!st.empty() && a[i] >= a[st.top().fi]) { curMin = min(curMin, st.top().se); st.pop(); } int res = min(curMin, f[X - 1][st.top().fi]); f[X][i] = f[X][st.top().fi]; f[X][i] = min(f[X][i], res + a[i]); curMin = min(curMin, f[X - 1][i]); st.push({i, curMin}); } } // for(int X = 1; X <= K; X++) { // for(int i = 1; i <= n; i++) { // cout << "#: " << X << ' ' << i << "\t" << f[X][i] << endl; // } // } cout << f[K][n] << '\n'; } void process() { } int32_t main() { if(fopen("trash.inp", "r")) freopen("trash.inp", "r", stdin), freopen("trash.out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); int T = 1; while(T--) { in(); process(); } }

Compilation message (stderr)

blocks.cpp: In function 'int32_t main()':
blocks.cpp:52:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |   freopen("trash.inp", "r", stdin), freopen("trash.out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:52:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |   freopen("trash.inp", "r", stdin), freopen("trash.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...