답안 #543389

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
543389 2022-03-30T13:11:53 Z fcw Feast (NOI19_feast) C++17
40 / 100
315 ms 15064 KB
#include <bits/stdc++.h>
#define st first
#define nd second
using lint = int64_t;
constexpr int mod = int(1e9) + 7;
constexpr int inf = 0x3f3f3f3f;
constexpr int ninf = 0xcfcfcfcf;
constexpr lint linf = 0x3f3f3f3f3f3f3f3f;
const long double pi = acosl(-1.0);
// Returns -1 if a < b, 0 if a = b and 1 if a > b.
int cmp_double(double a, double b = 0, double eps = 1e-9) {
	return a + eps > b ? b + eps > a ? 0 : 1 : -1;
}
using namespace std;

const lint INF = 3e14 + 10;

int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	int n, k;
	cin>>n>>k;
	vector<lint>a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	double lo = 0, hi = INF;
	for(int i=0;i<100;i++){
		double mid = (lo + hi) / 2;
		vector<array<pair<double, lint>, 2>>dp(n+1); 
		dp[0][0] = {0, 0}, dp[0][1] = {-INF, 0};
		for(int i=0;i<n;i++){
			dp[i+1][1] = max(make_pair(dp[i][1].st + a[i], dp[i][1].nd), 
					make_pair(dp[i][0].st + a[i] - mid, dp[i][0].nd + 1));
				
			dp[i+1][0] = max(dp[i][0], dp[i][1]);	
		}
		if(max(dp[n][0], dp[n][1]).nd >= k) lo = mid;
		else hi = mid; 
	}
	double mid = hi;
	vector<array<double, 2>>dp(n+1); 
	dp[0][0] = 0, dp[0][1] = -INF;
	for(int i=0;i<n;i++){
		dp[i+1][1] = max(dp[i][1] + a[i], dp[i][0] + a[i] - mid);
		dp[i+1][0] = max(dp[i][0], dp[i][1]);	
	}
	cout<< lint(max(dp[n][0], dp[n][1]) + mid * k + 1e-9)<<"\n";	
	
		
	
	

	return 0;
}
/*
[  ]Leu o problema certo???
[  ]Ver se precisa de long long
[  ]Viu o limite dos fors (é n? é m?)
[  ]Tamanho do vetor, será que é 2e5 em vez de 1e5??
[  ]Testar sample
[  ]Testar casos de  borda
[  ]1LL no 1LL << i
[  ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?)
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 224 ms 14488 KB Output is correct
2 Correct 233 ms 14736 KB Output is correct
3 Correct 233 ms 14940 KB Output is correct
4 Correct 252 ms 14808 KB Output is correct
5 Correct 215 ms 14756 KB Output is correct
6 Correct 216 ms 14488 KB Output is correct
7 Correct 232 ms 14412 KB Output is correct
8 Correct 253 ms 14736 KB Output is correct
9 Correct 218 ms 14516 KB Output is correct
10 Correct 242 ms 14676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 220 ms 12892 KB Output is correct
2 Correct 224 ms 13132 KB Output is correct
3 Correct 230 ms 12884 KB Output is correct
4 Correct 240 ms 12976 KB Output is correct
5 Correct 230 ms 14540 KB Output is correct
6 Correct 244 ms 12840 KB Output is correct
7 Correct 220 ms 13132 KB Output is correct
8 Correct 238 ms 14884 KB Output is correct
9 Correct 248 ms 14432 KB Output is correct
10 Correct 206 ms 13044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 314 ms 14920 KB Output is correct
2 Correct 290 ms 14768 KB Output is correct
3 Correct 308 ms 14904 KB Output is correct
4 Correct 298 ms 14764 KB Output is correct
5 Correct 284 ms 14884 KB Output is correct
6 Correct 315 ms 14968 KB Output is correct
7 Correct 290 ms 15064 KB Output is correct
8 Correct 277 ms 14896 KB Output is correct
9 Correct 295 ms 15060 KB Output is correct
10 Correct 303 ms 15064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Incorrect 1 ms 340 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Incorrect 1 ms 340 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 224 ms 14488 KB Output is correct
2 Correct 233 ms 14736 KB Output is correct
3 Correct 233 ms 14940 KB Output is correct
4 Correct 252 ms 14808 KB Output is correct
5 Correct 215 ms 14756 KB Output is correct
6 Correct 216 ms 14488 KB Output is correct
7 Correct 232 ms 14412 KB Output is correct
8 Correct 253 ms 14736 KB Output is correct
9 Correct 218 ms 14516 KB Output is correct
10 Correct 242 ms 14676 KB Output is correct
11 Correct 220 ms 12892 KB Output is correct
12 Correct 224 ms 13132 KB Output is correct
13 Correct 230 ms 12884 KB Output is correct
14 Correct 240 ms 12976 KB Output is correct
15 Correct 230 ms 14540 KB Output is correct
16 Correct 244 ms 12840 KB Output is correct
17 Correct 220 ms 13132 KB Output is correct
18 Correct 238 ms 14884 KB Output is correct
19 Correct 248 ms 14432 KB Output is correct
20 Correct 206 ms 13044 KB Output is correct
21 Correct 314 ms 14920 KB Output is correct
22 Correct 290 ms 14768 KB Output is correct
23 Correct 308 ms 14904 KB Output is correct
24 Correct 298 ms 14764 KB Output is correct
25 Correct 284 ms 14884 KB Output is correct
26 Correct 315 ms 14968 KB Output is correct
27 Correct 290 ms 15064 KB Output is correct
28 Correct 277 ms 14896 KB Output is correct
29 Correct 295 ms 15060 KB Output is correct
30 Correct 303 ms 15064 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 320 KB Output is correct
36 Correct 1 ms 316 KB Output is correct
37 Correct 1 ms 316 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 320 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Incorrect 1 ms 340 KB Output isn't correct
42 Halted 0 ms 0 KB -