이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimization "Ofast"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e5 + 6;
const ll Log2 = 19;
const ll inf = 1e16 + 7;
typedef pair<ll,ll> LL;
ll n,k,a[N],dp[N][101],mn[N],MaxSeg[N],L[N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "tst"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
}
cin>>n>>k;
for (ll i = 1;i <= n;i++) cin>>a[i];
for (ll i = 0;i <= n;i++)
for (ll j = 0;j <= k;j++) dp[i][j] = inf;
ll curmax = 0;
for (ll i = 1;i <= n;i++) curmax = max(curmax,a[i]),dp[i][1] = curmax;
for (ll j = 2;j <= k;j++){
stack<LL> st; /// first = minval second = index
for (ll i = j;i <= n;i++){
ll now = dp[i - 1][j - 1];
while(!st.empty() && a[st.top().sc] <= a[i]) now = min(now,st.top().fs),st.pop();
dp[i][j] = now + a[i];
if (st.size()) dp[i][j] = min(dp[i][j],dp[st.top().sc][j]);
st.push({now,i});
}
}
cout<<dp[n][k];
}
컴파일 시 표준 에러 (stderr) 메시지
blocks.cpp:1: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
1 | #pragma GCC optimization "Ofast"
|
blocks.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
2 | #pragma GCC optimization "unroll-loop"
|
blocks.cpp:13:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0000000000000008e+16' to '2147483647' [-Woverflow]
13 | const ll inf = 1e16 + 7;
| ~~~~~^~~
blocks.cpp: In function 'int main()':
blocks.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
23 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |