답안 #938587

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938587 2024-03-05T10:43:26 Z Lilypad Feast (NOI19_feast) C++14
21 / 100
37 ms 72272 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 = 1503;

ll n,k,sum,b[N];
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];
	}
	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 Runtime error 37 ms 72272 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 35676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 34 ms 72016 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 35672 KB Output is correct
2 Correct 5 ms 35676 KB Output is correct
3 Correct 6 ms 35676 KB Output is correct
4 Correct 5 ms 35672 KB Output is correct
5 Correct 6 ms 35804 KB Output is correct
6 Correct 5 ms 35676 KB Output is correct
7 Correct 5 ms 35676 KB Output is correct
8 Correct 6 ms 35676 KB Output is correct
9 Correct 5 ms 35676 KB Output is correct
10 Correct 5 ms 35800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 35672 KB Output is correct
2 Correct 5 ms 35676 KB Output is correct
3 Correct 6 ms 35676 KB Output is correct
4 Correct 5 ms 35672 KB Output is correct
5 Correct 6 ms 35804 KB Output is correct
6 Correct 5 ms 35676 KB Output is correct
7 Correct 5 ms 35676 KB Output is correct
8 Correct 6 ms 35676 KB Output is correct
9 Correct 5 ms 35676 KB Output is correct
10 Correct 5 ms 35800 KB Output is correct
11 Correct 5 ms 35676 KB Output is correct
12 Correct 5 ms 35676 KB Output is correct
13 Correct 5 ms 35752 KB Output is correct
14 Correct 5 ms 35676 KB Output is correct
15 Correct 7 ms 35760 KB Output is correct
16 Correct 5 ms 35676 KB Output is correct
17 Correct 5 ms 35676 KB Output is correct
18 Correct 6 ms 35744 KB Output is correct
19 Correct 5 ms 35676 KB Output is correct
20 Correct 5 ms 35704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 35672 KB Output is correct
2 Correct 5 ms 35676 KB Output is correct
3 Correct 6 ms 35676 KB Output is correct
4 Correct 5 ms 35672 KB Output is correct
5 Correct 6 ms 35804 KB Output is correct
6 Correct 5 ms 35676 KB Output is correct
7 Correct 5 ms 35676 KB Output is correct
8 Correct 6 ms 35676 KB Output is correct
9 Correct 5 ms 35676 KB Output is correct
10 Correct 5 ms 35800 KB Output is correct
11 Correct 5 ms 35676 KB Output is correct
12 Correct 5 ms 35676 KB Output is correct
13 Correct 5 ms 35752 KB Output is correct
14 Correct 5 ms 35676 KB Output is correct
15 Correct 7 ms 35760 KB Output is correct
16 Correct 5 ms 35676 KB Output is correct
17 Correct 5 ms 35676 KB Output is correct
18 Correct 6 ms 35744 KB Output is correct
19 Correct 5 ms 35676 KB Output is correct
20 Correct 5 ms 35704 KB Output is correct
21 Incorrect 10 ms 35820 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 37 ms 72272 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -