답안 #938597

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938597 2024-03-05T10:54:26 Z Lilypad Feast (NOI19_feast) C++14
71 / 100
128 ms 74040 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define pb push_back
#define fi first
#define se second

const ll N = 2003;

ll n,k,sum,b[300005],pref[300005];
ll mins,pos,idx;
vector<ll> a;
ll memo[N][N][2];

ll dp(ll x, ll y, ll stat) {
	if(x == idx+1) return 0;
	ll tmp = memo[x][y][stat];
	if(tmp != -1) return tmp;
	if(stat == 0) {
		tmp = dp(x+1,y,0);
		if(y > 0) {
			tmp = max(tmp,dp(x+1,y-1,1)+a[x]);
		}
	}
	else {
		tmp = max(dp(x+1,y,0),dp(x+1,y,1)+a[x]);
	}
	return memo[x][y][stat] = tmp;
}

int main() {
	memset(memo,-1,sizeof(memo));
	cin >> n >> k;
	for(int i=1; i<=n; i++) {
		cin >> b[i];
	}
	if(k == 1) {
		mins = 0;
		ll ans = 0;
		for(int i=1; i<=n; i++) {
			pref[i] = pref[i-1] + b[i];
			ans = max(ans,pref[i]-mins);
			mins = min(mins,pref[i]);
		}
		cout << ans << endl;
		return 0;
	}
	a.pb(0);
	for(int i=1; i<=n; i++) {
		if(b[i] >= 0) {
			sum += b[i];
			if(mins < 0) {
				a.pb(mins);
				mins = 0;
			}
		}
		else {
			mins += b[i];
			if(sum > 0) {
				a.pb(sum);
				sum = 0;
				pos++;
			}
		}
	}
	if(sum > 0) {
		a.pb(sum);
		pos++;
	}
	if(mins < 0) a.pb(mins);
	idx = a.size()-1;
	cout << dp(1,k,0) << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 67788 KB Output is correct
2 Correct 88 ms 67772 KB Output is correct
3 Correct 89 ms 67920 KB Output is correct
4 Correct 87 ms 67668 KB Output is correct
5 Correct 86 ms 67804 KB Output is correct
6 Correct 88 ms 67668 KB Output is correct
7 Correct 90 ms 67804 KB Output is correct
8 Correct 88 ms 67668 KB Output is correct
9 Correct 87 ms 67664 KB Output is correct
10 Correct 88 ms 67804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 67740 KB Output is correct
2 Correct 50 ms 67912 KB Output is correct
3 Correct 51 ms 67804 KB Output is correct
4 Correct 51 ms 67808 KB Output is correct
5 Correct 86 ms 67664 KB Output is correct
6 Correct 50 ms 67716 KB Output is correct
7 Correct 51 ms 67672 KB Output is correct
8 Correct 88 ms 67664 KB Output is correct
9 Correct 86 ms 67664 KB Output is correct
10 Correct 50 ms 67712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 67680 KB Output is correct
2 Correct 94 ms 67832 KB Output is correct
3 Correct 128 ms 67692 KB Output is correct
4 Correct 93 ms 67868 KB Output is correct
5 Correct 93 ms 67668 KB Output is correct
6 Correct 94 ms 67888 KB Output is correct
7 Correct 94 ms 67920 KB Output is correct
8 Correct 93 ms 67664 KB Output is correct
9 Correct 101 ms 68144 KB Output is correct
10 Correct 116 ms 67768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 66140 KB Output is correct
2 Correct 8 ms 66140 KB Output is correct
3 Correct 9 ms 66140 KB Output is correct
4 Correct 9 ms 66252 KB Output is correct
5 Correct 8 ms 66136 KB Output is correct
6 Correct 8 ms 66140 KB Output is correct
7 Correct 9 ms 66204 KB Output is correct
8 Correct 9 ms 66136 KB Output is correct
9 Correct 8 ms 66136 KB Output is correct
10 Correct 8 ms 66140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 66140 KB Output is correct
2 Correct 8 ms 66140 KB Output is correct
3 Correct 9 ms 66140 KB Output is correct
4 Correct 9 ms 66252 KB Output is correct
5 Correct 8 ms 66136 KB Output is correct
6 Correct 8 ms 66140 KB Output is correct
7 Correct 9 ms 66204 KB Output is correct
8 Correct 9 ms 66136 KB Output is correct
9 Correct 8 ms 66136 KB Output is correct
10 Correct 8 ms 66140 KB Output is correct
11 Correct 9 ms 66140 KB Output is correct
12 Correct 10 ms 66140 KB Output is correct
13 Correct 8 ms 66140 KB Output is correct
14 Correct 8 ms 66140 KB Output is correct
15 Correct 9 ms 66140 KB Output is correct
16 Correct 8 ms 66140 KB Output is correct
17 Correct 9 ms 66392 KB Output is correct
18 Correct 9 ms 66140 KB Output is correct
19 Correct 8 ms 66152 KB Output is correct
20 Correct 9 ms 66236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 66140 KB Output is correct
2 Correct 8 ms 66140 KB Output is correct
3 Correct 9 ms 66140 KB Output is correct
4 Correct 9 ms 66252 KB Output is correct
5 Correct 8 ms 66136 KB Output is correct
6 Correct 8 ms 66140 KB Output is correct
7 Correct 9 ms 66204 KB Output is correct
8 Correct 9 ms 66136 KB Output is correct
9 Correct 8 ms 66136 KB Output is correct
10 Correct 8 ms 66140 KB Output is correct
11 Correct 9 ms 66140 KB Output is correct
12 Correct 10 ms 66140 KB Output is correct
13 Correct 8 ms 66140 KB Output is correct
14 Correct 8 ms 66140 KB Output is correct
15 Correct 9 ms 66140 KB Output is correct
16 Correct 8 ms 66140 KB Output is correct
17 Correct 9 ms 66392 KB Output is correct
18 Correct 9 ms 66140 KB Output is correct
19 Correct 8 ms 66152 KB Output is correct
20 Correct 9 ms 66236 KB Output is correct
21 Correct 13 ms 66136 KB Output is correct
22 Correct 16 ms 66140 KB Output is correct
23 Correct 16 ms 66256 KB Output is correct
24 Correct 13 ms 66140 KB Output is correct
25 Correct 14 ms 66216 KB Output is correct
26 Correct 12 ms 66140 KB Output is correct
27 Correct 15 ms 66136 KB Output is correct
28 Correct 10 ms 66136 KB Output is correct
29 Correct 10 ms 66548 KB Output is correct
30 Correct 9 ms 66136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 67788 KB Output is correct
2 Correct 88 ms 67772 KB Output is correct
3 Correct 89 ms 67920 KB Output is correct
4 Correct 87 ms 67668 KB Output is correct
5 Correct 86 ms 67804 KB Output is correct
6 Correct 88 ms 67668 KB Output is correct
7 Correct 90 ms 67804 KB Output is correct
8 Correct 88 ms 67668 KB Output is correct
9 Correct 87 ms 67664 KB Output is correct
10 Correct 88 ms 67804 KB Output is correct
11 Correct 50 ms 67740 KB Output is correct
12 Correct 50 ms 67912 KB Output is correct
13 Correct 51 ms 67804 KB Output is correct
14 Correct 51 ms 67808 KB Output is correct
15 Correct 86 ms 67664 KB Output is correct
16 Correct 50 ms 67716 KB Output is correct
17 Correct 51 ms 67672 KB Output is correct
18 Correct 88 ms 67664 KB Output is correct
19 Correct 86 ms 67664 KB Output is correct
20 Correct 50 ms 67712 KB Output is correct
21 Correct 96 ms 67680 KB Output is correct
22 Correct 94 ms 67832 KB Output is correct
23 Correct 128 ms 67692 KB Output is correct
24 Correct 93 ms 67868 KB Output is correct
25 Correct 93 ms 67668 KB Output is correct
26 Correct 94 ms 67888 KB Output is correct
27 Correct 94 ms 67920 KB Output is correct
28 Correct 93 ms 67664 KB Output is correct
29 Correct 101 ms 68144 KB Output is correct
30 Correct 116 ms 67768 KB Output is correct
31 Correct 8 ms 66140 KB Output is correct
32 Correct 8 ms 66140 KB Output is correct
33 Correct 9 ms 66140 KB Output is correct
34 Correct 9 ms 66252 KB Output is correct
35 Correct 8 ms 66136 KB Output is correct
36 Correct 8 ms 66140 KB Output is correct
37 Correct 9 ms 66204 KB Output is correct
38 Correct 9 ms 66136 KB Output is correct
39 Correct 8 ms 66136 KB Output is correct
40 Correct 8 ms 66140 KB Output is correct
41 Correct 9 ms 66140 KB Output is correct
42 Correct 10 ms 66140 KB Output is correct
43 Correct 8 ms 66140 KB Output is correct
44 Correct 8 ms 66140 KB Output is correct
45 Correct 9 ms 66140 KB Output is correct
46 Correct 8 ms 66140 KB Output is correct
47 Correct 9 ms 66392 KB Output is correct
48 Correct 9 ms 66140 KB Output is correct
49 Correct 8 ms 66152 KB Output is correct
50 Correct 9 ms 66236 KB Output is correct
51 Correct 13 ms 66136 KB Output is correct
52 Correct 16 ms 66140 KB Output is correct
53 Correct 16 ms 66256 KB Output is correct
54 Correct 13 ms 66140 KB Output is correct
55 Correct 14 ms 66216 KB Output is correct
56 Correct 12 ms 66140 KB Output is correct
57 Correct 15 ms 66136 KB Output is correct
58 Correct 10 ms 66136 KB Output is correct
59 Correct 10 ms 66548 KB Output is correct
60 Correct 9 ms 66136 KB Output is correct
61 Incorrect 127 ms 74040 KB Output isn't correct
62 Halted 0 ms 0 KB -