Submission #703981

# Submission time Handle Problem Language Result Execution time Memory
703981 2023-03-01T08:12:29 Z vjudge1 K blocks (IZhO14_blocks) C++17
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
const int mod=998244353, maxn=1e5+5;
int n, k, a[maxn], mindp, val, dp[105][maxn];
stack<pii> s;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> k;
	for(int i=1; i<=n; i++) cin >> a[i];
	for(int kel=1; kel<=k; kel++) {
		for(int i=kel; i<=n; i++) {
			mindp=dp[kel-1][i-1];
			while(!s.empty()&&a[s.top().fi]<=a[i]) {
				mindp=min(mindp, s.top().se);
				s.pop();
			}
			val=1e9;
			if(!s.empty()) val=dp[kel][s.top().fi];
			dp[kel][i]=min(val, mindp+a[i]);
			s.push({i, mindp});
		}
		while(!s.empty()) s.pop();
	}
	cout << dp[k][n] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -