Submission #91377

# Submission time Handle Problem Language Result Execution time Memory
91377 2018-12-27T09:21:42 Z Just_Solve_The_Problem K blocks (IZhO14_blocks) C++11
0 / 100
6 ms 688 KB
#include <bits/stdc++.h>

using namespace std;

const int N = (int)1e5 + 7;
const int inf = (int)1e9 + 7;

int n, k;
int dp[2][N];
int a[N];
main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	stack < pair < int, int > > st;
	for (int i = 1; i <= n; i++) {
		dp[1][i] = max(dp[1][i - 1], a[i]);
	}
	for (int i = 2; i <= k; i++) {
		while (!st.empty()) st.pop();
		st.push({dp[i & 1 ^ 1][i - 1], a[i]});
		dp[i & 1][i] = dp[i & 1 ^ 1][i - 1] + a[i];
		for (int j = i + 1; j <= n; j++) {
			int c = dp[i & 1 ^ 1][i - 1];
			while (!st.empty() && st.top().second <= a[j]) {
				c = min(c, st.top().first);
				st.pop();
			}
			if (st.empty() || st.top().first + st.top().second > c + a[j]) {
				st.push({c, a[j]});
			}
			dp[i & 1][j] = st.top().first + st.top().second;
		}
	}
	cout << dp[k & 1][n];
}

Compilation message

blocks.cpp:11:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
blocks.cpp: In function 'int main()':
blocks.cpp:22:17: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   st.push({dp[i & 1 ^ 1][i - 1], a[i]});
               ~~^~~
blocks.cpp:23:23: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   dp[i & 1][i] = dp[i & 1 ^ 1][i - 1] + a[i];
                     ~~^~~
blocks.cpp:25:17: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
    int c = dp[i & 1 ^ 1][i - 1];
               ~~^~~
blocks.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~~
blocks.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 528 KB Output is correct
6 Correct 2 ms 552 KB Output is correct
7 Correct 2 ms 556 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 2 ms 560 KB Output is correct
10 Correct 2 ms 568 KB Output is correct
11 Incorrect 2 ms 612 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 628 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 656 KB Output is correct
4 Correct 2 ms 660 KB Output is correct
5 Correct 2 ms 664 KB Output is correct
6 Correct 2 ms 668 KB Output is correct
7 Correct 2 ms 672 KB Output is correct
8 Correct 2 ms 680 KB Output is correct
9 Correct 2 ms 680 KB Output is correct
10 Correct 2 ms 680 KB Output is correct
11 Incorrect 2 ms 680 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 688 KB Output isn't correct
2 Halted 0 ms 0 KB -