Submission #883725

# Submission time Handle Problem Language Result Execution time Memory
883725 2023-12-05T20:17:30 Z alexdd K blocks (IZhO14_blocks) C++17
32 / 100
1 ms 2648 KB
#include<iostream>
#include<deque>
using namespace std;
const int NRIT = 10;
const int INF = 1e9;
int n,k;
int a[100005];
int tole[100005];
int tori[100005];
int dp[100005][105];
signed main()
{
    cin>>n>>k;
    deque<int> dq;
    int mxm=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        mxm = max(mxm,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);
        for(int j=1;j<=k;j++)
            dp[i][j]=INF;
        dp[i][1] = mxm;
    }
    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++)
        dp[0][i]=INF;
    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]);
            for(int x=i;x<min(tori[i],i+NRIT);x++)
                dp[x][j] = min(dp[x][j], aux + a[i]);
            for(int x=tori[i]-1;x>=max(i,tori[i]-NRIT);x--)
                dp[x][j] = min(dp[x][j], aux + a[i]);
        }
    }
    cout<<dp[n][k];
    return 0;
}
/**
10 5
1 9 1 9 1 9 1 9 1 9
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 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 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 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 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 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 2648 KB Output is correct
11 Correct 0 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 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 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 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 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 2396 KB Output is correct
19 Correct 0 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 1 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 1 ms 2648 KB Output is correct
29 Correct 0 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 0 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Incorrect 1 ms 2396 KB Output isn't correct
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 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 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 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 2396 KB Output is correct
19 Correct 0 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 1 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 1 ms 2648 KB Output is correct
29 Correct 0 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 0 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Incorrect 1 ms 2396 KB Output isn't correct
40 Halted 0 ms 0 KB -