답안 #588039

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
588039 2022-07-02T16:28:39 Z Temmie Feast (NOI19_feast) C++17
41 / 100
1000 ms 38452 KB
#include <bits/stdc++.h>

typedef std::pair <long long, int> pa;

int n, k;
std::vector <int> a;

pa g(long long l) {
	std::vector <std::vector <pa>> dp(n, std::vector <pa> (2, { -1, -1 }));
	auto f = [&] (auto&& self, int i, bool is) -> pa {
		if (i >= n) {
			return { 0, 0 };
		}
		if (dp[i][is].second != -1) {
			return dp[i][is];
		}
		dp[i][is] = self(self, i + 1, false);
		pa cand = self(self, i + 1, true);
		cand.second += !is;
		cand.first += a[i];
		cand.first -= l * !is;
		dp[i][is] = std::max(dp[i][is], cand);
		return dp[i][is];
	};
	return f(f, 0, false);
}

int main() {
	std::ios::sync_with_stdio(0); std::cin.tie(0);
	
	std::cin >> n >> k;
	a.resize(n);
	for (int& x : a) {
		std::cin >> x;
	}
	long long l = 0, r = 1LL << 42, ans = 0;
	while (l <= r) {
		long long mid = (l + r) >> 1;
		pa val = g(mid);
		if (val.second > k) {
			l = mid + 1;
		} else {
			r = mid - 1;
			ans = val.first + mid * k;
		}
	}
	std::cout << ans << "\n";
	
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1079 ms 38452 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1058 ms 36496 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1059 ms 38320 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 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 0 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 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 2 ms 464 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 2 ms 464 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 9 ms 468 KB Output is correct
22 Correct 7 ms 468 KB Output is correct
23 Correct 6 ms 468 KB Output is correct
24 Correct 6 ms 552 KB Output is correct
25 Correct 7 ms 468 KB Output is correct
26 Correct 6 ms 556 KB Output is correct
27 Correct 6 ms 468 KB Output is correct
28 Correct 8 ms 468 KB Output is correct
29 Correct 7 ms 552 KB Output is correct
30 Correct 7 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1079 ms 38452 KB Time limit exceeded
2 Halted 0 ms 0 KB -