Submission #158336

# Submission time Handle Problem Language Result Execution time Memory
158336 2019-10-16T13:52:39 Z gemini_man K blocks (IZhO14_blocks) C++11
0 / 100
81 ms 82680 KB
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
using namespace std;
#define int long long
const int N = 100005;
const int K = 105;
const int INF = 2e9;
int n,k;
int dp[N][K];
int a[N];
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	// freopen("BLOCKS_IZHO.inp", "r", stdin);
	// freopen("BLOCKS_IZHO.out", "w", stdout);
	cin >> n >> k;
	up(i,1,n) cin >> a[i];
	int curMax = 0;
	memset(dp, 0x3f, sizeof(dp));
	dp[0][1] = 0;
	up(i,1,n)	dp[i][1] = max(dp[i-1][1], a[i]);
	vector< pair<int,int> > sk;
	for(int j = 2; j <= k ;++j){
		for( int i = j;i <= n;++i){
			int minF = dp[i-1][j-1];
			// first = value
			// second = id
			while (!sk.empty() && a[sk.back().second] <= a[i]){
				minF = min (minF, sk.back().first);
				sk.pop_back();
			}
			dp[i][j] = min(dp[sk.empty() ? 0 : sk.back().second][j], minF + a[i]);
			sk.push_back(pair<int,int> (minF, i));
		}
	}
	cout << dp[n][k];
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:20:6: warning: unused variable 'curMax' [-Wunused-variable]
  int curMax = 0;
      ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 70 ms 82552 KB Output is correct
2 Correct 70 ms 82552 KB Output is correct
3 Correct 74 ms 82460 KB Output is correct
4 Correct 81 ms 82556 KB Output is correct
5 Correct 73 ms 82544 KB Output is correct
6 Correct 70 ms 82524 KB Output is correct
7 Correct 70 ms 82552 KB Output is correct
8 Correct 71 ms 82680 KB Output is correct
9 Correct 70 ms 82552 KB Output is correct
10 Incorrect 70 ms 82552 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 75 ms 82612 KB Output is correct
2 Correct 79 ms 82512 KB Output is correct
3 Correct 70 ms 82552 KB Output is correct
4 Correct 70 ms 82472 KB Output is correct
5 Correct 70 ms 82552 KB Output is correct
6 Correct 70 ms 82612 KB Output is correct
7 Correct 70 ms 82552 KB Output is correct
8 Correct 73 ms 82620 KB Output is correct
9 Correct 71 ms 82628 KB Output is correct
10 Incorrect 70 ms 82488 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 70 ms 82552 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 82556 KB Output isn't correct
2 Halted 0 ms 0 KB -