답안 #543391

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
543391 2022-03-30T13:14:06 Z fcw Feast (NOI19_feast) C++17
71 / 100
431 ms 14700 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(round(max(dp[n][0], dp[n][1]) + mid * k))<<"\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 232 ms 11692 KB Output is correct
2 Correct 250 ms 11860 KB Output is correct
3 Correct 242 ms 11980 KB Output is correct
4 Correct 229 ms 11932 KB Output is correct
5 Correct 243 ms 11860 KB Output is correct
6 Correct 266 ms 11684 KB Output is correct
7 Correct 242 ms 11596 KB Output is correct
8 Correct 237 ms 11920 KB Output is correct
9 Correct 232 ms 11692 KB Output is correct
10 Correct 247 ms 11852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 11732 KB Output is correct
2 Correct 248 ms 12016 KB Output is correct
3 Correct 229 ms 11784 KB Output is correct
4 Correct 225 ms 11860 KB Output is correct
5 Correct 250 ms 11696 KB Output is correct
6 Correct 221 ms 11724 KB Output is correct
7 Correct 240 ms 11980 KB Output is correct
8 Correct 240 ms 11888 KB Output is correct
9 Correct 256 ms 11616 KB Output is correct
10 Correct 232 ms 11908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 307 ms 11944 KB Output is correct
2 Correct 319 ms 11760 KB Output is correct
3 Correct 293 ms 11908 KB Output is correct
4 Correct 292 ms 11768 KB Output is correct
5 Correct 289 ms 11848 KB Output is correct
6 Correct 298 ms 11912 KB Output is correct
7 Correct 306 ms 12024 KB Output is correct
8 Correct 312 ms 11844 KB Output is correct
9 Correct 317 ms 11984 KB Output is correct
10 Correct 295 ms 12008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 260 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 260 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 260 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 356 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 3 ms 364 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 360 KB Output is correct
29 Correct 2 ms 420 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 232 ms 11692 KB Output is correct
2 Correct 250 ms 11860 KB Output is correct
3 Correct 242 ms 11980 KB Output is correct
4 Correct 229 ms 11932 KB Output is correct
5 Correct 243 ms 11860 KB Output is correct
6 Correct 266 ms 11684 KB Output is correct
7 Correct 242 ms 11596 KB Output is correct
8 Correct 237 ms 11920 KB Output is correct
9 Correct 232 ms 11692 KB Output is correct
10 Correct 247 ms 11852 KB Output is correct
11 Correct 219 ms 11732 KB Output is correct
12 Correct 248 ms 12016 KB Output is correct
13 Correct 229 ms 11784 KB Output is correct
14 Correct 225 ms 11860 KB Output is correct
15 Correct 250 ms 11696 KB Output is correct
16 Correct 221 ms 11724 KB Output is correct
17 Correct 240 ms 11980 KB Output is correct
18 Correct 240 ms 11888 KB Output is correct
19 Correct 256 ms 11616 KB Output is correct
20 Correct 232 ms 11908 KB Output is correct
21 Correct 307 ms 11944 KB Output is correct
22 Correct 319 ms 11760 KB Output is correct
23 Correct 293 ms 11908 KB Output is correct
24 Correct 292 ms 11768 KB Output is correct
25 Correct 289 ms 11848 KB Output is correct
26 Correct 298 ms 11912 KB Output is correct
27 Correct 306 ms 12024 KB Output is correct
28 Correct 312 ms 11844 KB Output is correct
29 Correct 317 ms 11984 KB Output is correct
30 Correct 295 ms 12008 KB Output is correct
31 Correct 1 ms 260 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 316 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 316 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 2 ms 340 KB Output is correct
53 Correct 2 ms 340 KB Output is correct
54 Correct 2 ms 356 KB Output is correct
55 Correct 2 ms 340 KB Output is correct
56 Correct 3 ms 364 KB Output is correct
57 Correct 2 ms 340 KB Output is correct
58 Correct 2 ms 360 KB Output is correct
59 Correct 2 ms 420 KB Output is correct
60 Correct 2 ms 340 KB Output is correct
61 Incorrect 431 ms 14700 KB Output isn't correct
62 Halted 0 ms 0 KB -