Submission #152831

# Submission time Handle Problem Language Result Execution time Memory
152831 2019-09-09T17:57:05 Z vex K blocks (IZhO14_blocks) C++14
53 / 100
1000 ms 50296 KB
#include<bits/stdc++.h>
#define maxn 100005
#define INF (int)(1e9 + 77)
using namespace std;
 
int n,k;
int a[maxn];
int dp[maxn][102];
int lv[maxn];
 
 
int minn[maxn][22];
void build(int ind)
{
	for(int d=0;(1<<d)<=n+1;d++)
    {
      	for(int i=0;i+(1<<d)-1<=n;i++)
        {
          	if(d==0)minn[i][0]=dp[i][ind];
          	else
            {
              	minn[i][d]=min( minn[i][d-1], minn[i+(1<<(d-1))][d-1]);
            }
        }
    }
}
 
int query(int lt,int rt)
{
	int d=log2(rt-lt+1);
  	return min( minn[lt][d], minn[rt-(1<<d)+1][d]);
}
 
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	
	stack<int>ms;
	ms.push(0);
	a[0]=INF;
	for(int i=1;i<=n;i++)
	{
		while(!ms.empty())
		{
			int vrh=ms.top();
			if(a[vrh]<=a[i])
			{
				ms.pop();
			}
			else break;
		}
		
		lv[i]=ms.top();
		ms.push(i);
	}
	
	//for(int i=1;i<=n;i++)cout<<lv[i]<<" ";cout<<endl;
	
	for(int i=0;i<=n;i++)
		for(int j=0;j<=k;j++)dp[i][j]=INF;
	dp[0][0]=0;
	
	for(int i=1;i<=n;i++)dp[i][0]=INF;
	for(int j=1;j<=k;j++)
	{
		build(j-1);
		for(int i=1;i<=n;i++)
		{
			dp[i][j]=min( dp[ lv[i] ][j], query(lv[i],i-1)+a[i]);
		}
	}
	
	cout<<dp[n][k];
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 424 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 424 KB Output is correct
13 Correct 2 ms 424 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 5404 KB Output is correct
2 Correct 30 ms 22648 KB Output is correct
3 Correct 63 ms 22616 KB Output is correct
4 Correct 397 ms 22776 KB Output is correct
5 Execution timed out 1072 ms 50296 KB Time limit exceeded
6 Halted 0 ms 0 KB -