제출 #1123430

#제출 시각아이디문제언어결과실행 시간메모리
1123430VinhLuuK개의 묶음 (IZhO14_blocks)C++20
100 / 100
121 ms4504 KiB
#include <bits/stdc++.h> //#define int long long #define ll long long #define all(lpv) lpv.begin(), lpv.end() #define fi first #define se second #define pot(x, y) lower_bound(x.begin(), x.end(), y) - x.begin() + 1 using namespace std; typedef pair<int,int> pii; const int N = 1e5 + 5; const int mod = 1e9 + 7; int n, kw; ll a[N], pf[N], mx[N], f[2][N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "v" if(fopen(task ".inp","r")){ freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } cin >> n >> kw; for(int i = 1; i <= n; i ++) { cin >> a[i]; } int pre = 0, nx = 1; ll _tmp = 0; for(int i = 1; i <= n; i ++) { _tmp = max(_tmp, a[i]); f[pre][i] = _tmp; } pf[0] = 1e16; for(int k = 2; k <= kw; k ++) { stack<int> st; for(int i = k; i <= n; i ++) { mx[i] = f[pre][i - 1]; while(!st.empty() && a[st.top()] <= a[i]) { mx[i] = min(mx[i], mx[st.top()]); st.pop(); } int last = (!st.empty() ? st.top() : 0); pf[i] = min(mx[i] + a[i], pf[last]); f[nx][i] = pf[i]; st.push(i); } swap(pre, nx); } cout << f[pre][n]; }

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

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