답안 #883702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
883702 2023-12-05T18:40:15 Z alexdd K개의 묶음 (IZhO14_blocks) C++17
53 / 100
1000 ms 222120 KB
#include<iostream>
#include<deque>
using namespace std;
const int INF = 1e9;
int n,k;
int a[100005];
int tole[100005];
int tori[100005];
int mymin(int x, int y)
{
    if(x==0)
        return y;
    if(y==0)
        return x;
}
int aint[270000][105];
int lazy[270000][105];
void build(int nod, int st, int dr, int c)
{
    aint[nod][c] = INF;
    lazy[nod][c] = INF;
    if(st==dr)
        return;
    int mij=(st+dr)/2;
    build(nod*2,st,mij,c);
    build(nod*2+1,mij+1,dr,c);
}
void propagate(int nod, int c)
{
    if(lazy[nod][c]==INF)
        return;
    aint[nod*2][c] = min(aint[nod*2][c], lazy[nod][c]);
    lazy[nod*2][c] = min(lazy[nod*2][c], lazy[nod][c]);
    aint[nod*2+1][c] = min(aint[nod*2+1][c], lazy[nod][c]);
    lazy[nod*2+1][c] = min(lazy[nod*2+1][c], lazy[nod][c]);
    lazy[nod][c]=INF;
}
void upd(int nod, int st, int dr, int le, int ri, int newv, int c)
{
    if(le>ri)
        return;
    if(le==st && dr==ri)
    {
        if(aint[nod][c]>newv)
        {
            aint[nod][c]=newv;
            lazy[nod][c]=newv;
        }
        return;
    }
    propagate(nod,c);
    int mij=(st+dr)/2;
    upd(nod*2,st,mij,le,min(mij,ri),newv,c);
    upd(nod*2+1,mij+1,dr,max(mij+1,le),ri,newv,c);
    aint[nod][c] = min(aint[nod*2][c],aint[nod*2+1][c]);
}
int qry(int nod, int st, int dr, int le, int ri, int c)
{
    if(le>ri)
        return INF;
    if(le==st && dr==ri)
        return aint[nod][c];
    propagate(nod,c);
    int mij=(st+dr)/2;
    return min(qry(nod*2,st,mij,le,min(mij,ri),c),
               qry(nod*2+1,mij+1,dr,max(mij+1,le),ri,c));
}

signed main()
{
    cin>>n>>k;
    deque<int> dq;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        while(!dq.empty() && a[dq.back()]<=a[i])
            dq.pop_back();
        if(dq.empty())
            tole[i]=0;
        else
            tole[i]=dq.back();
        dq.push_back(i);
    }
    dq.clear();
    for(int i=n;i>0;i--)
    {
        while(!dq.empty() && a[dq.back()]<=a[i])
            dq.pop_back();
        if(dq.empty())
            tori[i]=n+1;
        else
            tori[i]=dq.back();
        dq.push_back(i);
    }
    for(int i=1;i<=k;i++)
        build(1,0,n,i);
    int mxm=0;
    for(int i=1;i<=n;i++)
    {
        mxm = max(mxm,a[i]);
        upd(1,0,n,i,i,mxm,1);
    }
    for(int i=1;i<=n;i++)
    {
        //cout<<i<<"  "<<tole[i]<<" "<<tori[i]<<" zzz\n";
        for(int j=2;j<=k;j++)
        {
            //if(dp[tole[i]][j-1]==INF)
              //  continue;
            //cout<<i<<" "<<j<<" zzz\n";
           // dp[tori[i]-1][j] = min(dp[tori[i]-1][j], dp[tole[i]][j-1] + a[i]);
            int aux = INF;
            //for(int x=tole[i];x<i;x++)
              //  aux = min(aux, dp[x][j-1]);
            aux = qry(1,0,n,tole[i],i-1,j-1);
            //for(int x=i;x<tori[i];x++)
              //  dp[x][j] = min(dp[x][j], aux + a[i]);
            upd(1,0,n,i,tori[i]-1,aux+a[i],j);
        }
    }
    cout<<qry(1,0,n,n,n,k);
    return 0;
}
/**
10 5
1 9 1 9 1 9 1 9 1 9
*/

Compilation message

blocks.cpp: In function 'int mymin(int, int)':
blocks.cpp:15:1: warning: control reaches end of non-void function [-Wreturn-type]
   15 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 0 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 0 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 0 ms 2396 KB Output is correct
44 Correct 0 ms 2396 KB Output is correct
45 Correct 0 ms 2396 KB Output is correct
46 Correct 0 ms 2396 KB Output is correct
47 Correct 0 ms 2396 KB Output is correct
48 Correct 0 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 2 ms 4444 KB Output is correct
54 Correct 3 ms 4656 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 2 ms 4444 KB Output is correct
57 Correct 3 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 0 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 0 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 0 ms 2396 KB Output is correct
44 Correct 0 ms 2396 KB Output is correct
45 Correct 0 ms 2396 KB Output is correct
46 Correct 0 ms 2396 KB Output is correct
47 Correct 0 ms 2396 KB Output is correct
48 Correct 0 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 2 ms 4444 KB Output is correct
54 Correct 3 ms 4656 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 2 ms 4444 KB Output is correct
57 Correct 3 ms 4444 KB Output is correct
58 Correct 70 ms 31324 KB Output is correct
59 Correct 36 ms 114012 KB Output is correct
60 Correct 118 ms 114048 KB Output is correct
61 Correct 904 ms 114352 KB Output is correct
62 Execution timed out 1048 ms 222120 KB Time limit exceeded
63 Halted 0 ms 0 KB -