답안 #1057617

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1057617 2024-08-14T00:56:04 Z ghostlywalrus Feast (NOI19_feast) C++17
100 / 100
155 ms 10404 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;

#define int long long
#define PI pair<int,int>
#define f first
#define s second
#define pb push_back
#define szo(x) ((int)x.size())

const int INF = 1e18;
const int maxn = 3e5+10;

int n, k;
int nums[maxn];
int dp[maxn];
int cnt[maxn];

PI solve(int m){
	 for (int i = 0; i <= n; ++i) dp[i] = 0, cnt[i] = 0;
	 int best = 0;
	 int idbest = 0;
		
	 for (int i = 1; i <= n; ++i){
	 	dp[i] = dp[i-1];
		cnt[i] = cnt[i-1];
		best += nums[i];

		if (best-m > dp[i]){
	 		dp[i] = best-m;
			cnt[i] = cnt[idbest] + 1; 
		}

		if ((dp[i] > best) || ((dp[i] == best) && cnt[i] <= cnt[idbest])){
	 		best = dp[i];
			idbest = i;
		}
	 }

	 return {dp[n], cnt[n]}; 
}


int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> k;

	for (int i = 1; i <= n; ++i) cin >> nums[i];

	int x = 1e18;
	for (int b = 1e18; b >= 1; b >>= 1){
	 	while (x-b >= 0 && solve(x-b).s <= k) x -= b;
	}

	cout << solve(x).f + k * x << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 7260 KB Output is correct
2 Correct 18 ms 10196 KB Output is correct
3 Correct 18 ms 10332 KB Output is correct
4 Correct 18 ms 10316 KB Output is correct
5 Correct 18 ms 10332 KB Output is correct
6 Correct 19 ms 10076 KB Output is correct
7 Correct 20 ms 10228 KB Output is correct
8 Correct 21 ms 10168 KB Output is correct
9 Correct 18 ms 10048 KB Output is correct
10 Correct 18 ms 10296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 7420 KB Output is correct
2 Correct 62 ms 7256 KB Output is correct
3 Correct 62 ms 7420 KB Output is correct
4 Correct 12 ms 7260 KB Output is correct
5 Correct 68 ms 10048 KB Output is correct
6 Correct 62 ms 8520 KB Output is correct
7 Correct 12 ms 8540 KB Output is correct
8 Correct 69 ms 10332 KB Output is correct
9 Correct 69 ms 10200 KB Output is correct
10 Correct 12 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 7260 KB Output is correct
2 Correct 101 ms 7256 KB Output is correct
3 Correct 101 ms 7260 KB Output is correct
4 Correct 102 ms 7256 KB Output is correct
5 Correct 102 ms 7260 KB Output is correct
6 Correct 105 ms 7260 KB Output is correct
7 Correct 107 ms 7412 KB Output is correct
8 Correct 118 ms 7448 KB Output is correct
9 Correct 104 ms 7260 KB Output is correct
10 Correct 103 ms 7248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 0 ms 4444 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 0 ms 4444 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 7260 KB Output is correct
2 Correct 18 ms 10196 KB Output is correct
3 Correct 18 ms 10332 KB Output is correct
4 Correct 18 ms 10316 KB Output is correct
5 Correct 18 ms 10332 KB Output is correct
6 Correct 19 ms 10076 KB Output is correct
7 Correct 20 ms 10228 KB Output is correct
8 Correct 21 ms 10168 KB Output is correct
9 Correct 18 ms 10048 KB Output is correct
10 Correct 18 ms 10296 KB Output is correct
11 Correct 58 ms 7420 KB Output is correct
12 Correct 62 ms 7256 KB Output is correct
13 Correct 62 ms 7420 KB Output is correct
14 Correct 12 ms 7260 KB Output is correct
15 Correct 68 ms 10048 KB Output is correct
16 Correct 62 ms 8520 KB Output is correct
17 Correct 12 ms 8540 KB Output is correct
18 Correct 69 ms 10332 KB Output is correct
19 Correct 69 ms 10200 KB Output is correct
20 Correct 12 ms 8540 KB Output is correct
21 Correct 114 ms 7260 KB Output is correct
22 Correct 101 ms 7256 KB Output is correct
23 Correct 101 ms 7260 KB Output is correct
24 Correct 102 ms 7256 KB Output is correct
25 Correct 102 ms 7260 KB Output is correct
26 Correct 105 ms 7260 KB Output is correct
27 Correct 107 ms 7412 KB Output is correct
28 Correct 118 ms 7448 KB Output is correct
29 Correct 104 ms 7260 KB Output is correct
30 Correct 103 ms 7248 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 0 ms 4444 KB Output is correct
33 Correct 0 ms 4444 KB Output is correct
34 Correct 0 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 0 ms 4444 KB Output is correct
37 Correct 0 ms 4444 KB Output is correct
38 Correct 0 ms 4444 KB Output is correct
39 Correct 0 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 0 ms 4444 KB Output is correct
42 Correct 0 ms 4444 KB Output is correct
43 Correct 1 ms 4440 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 0 ms 4444 KB Output is correct
46 Correct 1 ms 4440 KB Output is correct
47 Correct 0 ms 4444 KB Output is correct
48 Correct 0 ms 4444 KB Output is correct
49 Correct 0 ms 4444 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4440 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 1 ms 4444 KB Output is correct
57 Correct 1 ms 4444 KB Output is correct
58 Correct 1 ms 4444 KB Output is correct
59 Correct 1 ms 4444 KB Output is correct
60 Correct 1 ms 4444 KB Output is correct
61 Correct 148 ms 10332 KB Output is correct
62 Correct 22 ms 10332 KB Output is correct
63 Correct 122 ms 10332 KB Output is correct
64 Correct 152 ms 10320 KB Output is correct
65 Correct 155 ms 10304 KB Output is correct
66 Correct 146 ms 10332 KB Output is correct
67 Correct 151 ms 10404 KB Output is correct
68 Correct 118 ms 10332 KB Output is correct
69 Correct 103 ms 10324 KB Output is correct
70 Correct 101 ms 10324 KB Output is correct