이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
#include <iomanip>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define vi vector<int>
#define pb push_back
//#define p push
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#pragma GCC optimize ("03,unroll-lopps")
#define double long double
const int mxn=1e5,inf=1e9;
int n,dp[2][mxn+10],l[mxn+10],v[mxn+10],k;
int32_t main(){
fastio
cin>>n>>k;
int mx=0;
for(int i=1;i<=n;i++)cin>>v[i],mx=max(mx,v[i]),dp[0][i]=mx;
n++;
stack<pii>st;
while(!st.empty())st.pop();
for(int j=1;j<k;j++){
for(int i=0;i<n;i++)dp[j&1][i]=inf;
for(int i=j+1;i<n;i++){
int g=dp[(j&1)^1][i-1];
while(!st.empty()&&(v[st.top().s]<=v[i]))g=min(g,st.top().f),st.pop();
g+=v[i];
if(!st.empty())g=min(g,dp[j&1][st.top().s]);
dp[j&1][i]=g;
st.push({g-v[i],i});
}
while(!st.empty())st.pop();
}
cout<<dp[(k&1)^1][n-1];
}
컴파일 시 표준 에러 (stderr) 메시지
blocks.cpp:32:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
32 | #pragma GCC optimize ("03,unroll-lopps")
| ^
blocks.cpp:36:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
36 | int32_t main(){
| ^
# | 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... |