답안 #1101515

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101515 2024-10-16T09:18:18 Z thanhhoang K개의 묶음 (IZhO14_blocks) C++14
0 / 100
76 ms 87880 KB
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+53;
int n,k,a[N][20],b[N][102],c[N],e[N],f[N][20];
stack<int>d;
void bui()
{
    for(int i=1;i<=n;i++) f[i][0]=e[i];
    for(int i=1;i<=log2(n);i++)
        for(int j=1;j+(1<<i)-1<=n;j++)
            f[j][i]=min(f[j][i-1],f[j+(1<<i-1)][i-1]);
}
int get(int l,int r)
{
    int o=log2(r-l+1);
    return min(f[l][o],f[r-(1<<o)+1][o]);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if(fopen("cc.inp","r"))
    {
        freopen("cc.inp","r",stdin);
        freopen("cc.out","w",stdout);
    }
    cin>>n>>k;
    a[0][0]=1e6+2;
    d.push(0);
    for(int i=1;i<=n;i++)
    {
        cin>>a[i][0];
        while(a[d.top()][0]<=a[i][0]) d.pop();
        c[i]=d.top()+1;
        if(!c[i]) c[i]=1;
        d.push(i);
    }
    memset(b,0x3f,sizeof b);
    a[0][0]=0;
    b[0][0]=0;
    for(int i=1;i<=k;i++)
    {
        bui();
        for(int j=i;j<=n;j++)
        {
            b[i][j]=min({b[i][j],b[i][c[j]-1],get(c[j],j-1)+a[j][0]});
            e[j]=b[i][j];
        }
    }

    cout<<b[k][n];
    return 0;
}

Compilation message

blocks.cpp: In function 'void bui()':
blocks.cpp:11:44: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   11 |             f[j][i]=min(f[j][i-1],f[j+(1<<i-1)][i-1]);
      |                                           ~^~
blocks.cpp: In function 'int main()':
blocks.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen("cc.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
blocks.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen("cc.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 61 ms 87852 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 76 ms 87880 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 61 ms 87852 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 61 ms 87852 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -