# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1101530 | ngongocbich | K개의 묶음 (IZhO14_blocks) | C++17 | 48 ms | 262144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define mask(k) (1<<(k))
using namespace std;
int n,k,a[1000001],dp[1000001][101],l[1000001],mx[1001][21];
stack<int> st;
int getmn(int l, int r)
{
int p=__lg(r-l+1);
return min(mx[l][p],mx[r-mask(p)+1][p]);
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen("w.inp","r",stdin);
freopen("w.out","w",stdout);
cin>>n>>k;
for (int i=1; i<=n; i++) cin>>a[i],mx[i][0]=0x3f;
for (int j=1; mask(j)<=n; j++)
for (int i=1; i+mask(j)-1<=n; i++)
mx[i][j]=min(mx[i][j-1],mx[i+mask(j-1)][j-1]);
for (int i=1; i<=n; i++)
{
while (!st.empty() && a[st.top()]<=a[i]) st.pop();
if (!st.empty()) l[i]=st.top(); else l[i]=0;
st.push(i);
}
memset(dp,0x3f,sizeof(dp));
dp[0][0]=0;
for (int i=1; i<=k; i++)
for (int j=1; j<=n; j++)
{
dp[i][j]=min(dp[i][j],a[j]+getmn(l[j],j-1));
dp[i][j]=min(dp[i][j],dp[i][l[j]]);
}
cout<<dp[k][n];
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |