제출 #1039072

#제출 시각아이디문제언어결과실행 시간메모리
1039072ttviet2805K개의 묶음 (IZhO14_blocks)C++14
100 / 100
241 ms82024 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)); f[0][0] = 0; for(int X = 1; X <= K; X++) { stack <II> st; 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 = curMin; if(!st.empty()) { 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(); } }

컴파일 시 표준 에러 (stderr) 메시지

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