답안 #1101530

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101530 2024-10-16T09:27:04 Z ngongocbich K개의 묶음 (IZhO14_blocks) C++17
0 / 100
48 ms 262144 KB
#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;
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen("w.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
blocks.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     freopen("w.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 42 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 48 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 42 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 42 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -