답안 #1017572

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017572 2024-07-09T08:55:04 Z vjudge1 Feast (NOI19_feast) C++17
100 / 100
214 ms 15188 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define int long long
#define pii pair<ll,ll>
const int mxN = 1e6 + 5;
const int mod = 1e9 + 7;
double lambda = 1e-8;
using namespace std;
bool operator>(pair<int,int> a,pair<int,int>b){
    return make_pair(a.F,-1 * a.S) > make_pair(b.F, -1 * b.S);
}
bool operator<(pair<int,int> a,pair<int,int>b){
    return make_pair(a.F,-1 * a.S) < make_pair(b.F, -1 * b.S);
}
int n,k;
int a[mxN];
pair<int,int> dp[mxN][2];
pair<int,int> num;
int ans;
bool solve(int lam){
    // cout<<lam<<'\n';
    for(int i = 0;i <= n;i++){
        dp[i][1] = make_pair(0,0);
        dp[i][0] = make_pair(0,0);
    }
    for(int i = 1;i <= n;i++){
        dp[i][0] = max(dp[i - 1][0],dp[i - 1][1]);
        dp[i][1] = make_pair(dp[i - 1][0].F + a[i] - lam,dp[i - 1][0].S + 1);
        if(i > 1) dp[i][1] = max(dp[i][1],make_pair(dp[i - 1][1].F + a[i],dp[i - 1][1].S));
        // cout<<dp[i][0].F<<' '<<dp[i][0].S<<' '<<dp[i][1].F<<' '<<dp[i][1].S<<'\n';
    }
    num = max(dp[n][0],dp[n][1]);
    // cout<<num.F<<' '<<num.S<<'\n';
    return (num.S <= k);
}
signed main(){
    // cout<<"TEST";
    cin >>n>>k;
    for(int i = 1;i <= n;i++) cin >>a[i];
    int l = 0,r = 1e16,md;
    int binit = 60;
    while(l < r){
        int md = (l + r) / 2;
        if(solve(md)){
            r = md;
            ans = num.F + num.S * md;
        }else l = md + 1;
    }
    cout<<ans;
}

Compilation message

feast.cpp: In function 'int main()':
feast.cpp:41:24: warning: unused variable 'md' [-Wunused-variable]
   41 |     int l = 0,r = 1e16,md;
      |                        ^~
feast.cpp:42:9: warning: unused variable 'binit' [-Wunused-variable]
   42 |     int binit = 60;
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 14928 KB Output is correct
2 Correct 122 ms 14932 KB Output is correct
3 Correct 123 ms 14760 KB Output is correct
4 Correct 138 ms 14928 KB Output is correct
5 Correct 123 ms 14932 KB Output is correct
6 Correct 153 ms 14932 KB Output is correct
7 Correct 127 ms 14928 KB Output is correct
8 Correct 122 ms 14764 KB Output is correct
9 Correct 157 ms 14772 KB Output is correct
10 Correct 128 ms 14932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 14764 KB Output is correct
2 Correct 92 ms 14928 KB Output is correct
3 Correct 90 ms 14928 KB Output is correct
4 Correct 112 ms 14928 KB Output is correct
5 Correct 123 ms 14928 KB Output is correct
6 Correct 95 ms 14928 KB Output is correct
7 Correct 89 ms 14928 KB Output is correct
8 Correct 125 ms 14932 KB Output is correct
9 Correct 122 ms 14772 KB Output is correct
10 Correct 95 ms 14940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 187 ms 14960 KB Output is correct
2 Correct 151 ms 14932 KB Output is correct
3 Correct 153 ms 14928 KB Output is correct
4 Correct 187 ms 14936 KB Output is correct
5 Correct 150 ms 14936 KB Output is correct
6 Correct 151 ms 15188 KB Output is correct
7 Correct 161 ms 14772 KB Output is correct
8 Correct 146 ms 14752 KB Output is correct
9 Correct 156 ms 14932 KB Output is correct
10 Correct 152 ms 14756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 2 ms 2396 KB Output is correct
23 Correct 2 ms 2392 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 2 ms 2392 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 14928 KB Output is correct
2 Correct 122 ms 14932 KB Output is correct
3 Correct 123 ms 14760 KB Output is correct
4 Correct 138 ms 14928 KB Output is correct
5 Correct 123 ms 14932 KB Output is correct
6 Correct 153 ms 14932 KB Output is correct
7 Correct 127 ms 14928 KB Output is correct
8 Correct 122 ms 14764 KB Output is correct
9 Correct 157 ms 14772 KB Output is correct
10 Correct 128 ms 14932 KB Output is correct
11 Correct 92 ms 14764 KB Output is correct
12 Correct 92 ms 14928 KB Output is correct
13 Correct 90 ms 14928 KB Output is correct
14 Correct 112 ms 14928 KB Output is correct
15 Correct 123 ms 14928 KB Output is correct
16 Correct 95 ms 14928 KB Output is correct
17 Correct 89 ms 14928 KB Output is correct
18 Correct 125 ms 14932 KB Output is correct
19 Correct 122 ms 14772 KB Output is correct
20 Correct 95 ms 14940 KB Output is correct
21 Correct 187 ms 14960 KB Output is correct
22 Correct 151 ms 14932 KB Output is correct
23 Correct 153 ms 14928 KB Output is correct
24 Correct 187 ms 14936 KB Output is correct
25 Correct 150 ms 14936 KB Output is correct
26 Correct 151 ms 15188 KB Output is correct
27 Correct 161 ms 14772 KB Output is correct
28 Correct 146 ms 14752 KB Output is correct
29 Correct 156 ms 14932 KB Output is correct
30 Correct 152 ms 14756 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 0 ms 2396 KB Output is correct
40 Correct 0 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 0 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2392 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2392 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 0 ms 2396 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 2 ms 2396 KB Output is correct
53 Correct 2 ms 2392 KB Output is correct
54 Correct 2 ms 2396 KB Output is correct
55 Correct 2 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2392 KB Output is correct
58 Correct 1 ms 2396 KB Output is correct
59 Correct 2 ms 2392 KB Output is correct
60 Correct 2 ms 2396 KB Output is correct
61 Correct 192 ms 14772 KB Output is correct
62 Correct 176 ms 14768 KB Output is correct
63 Correct 159 ms 14768 KB Output is correct
64 Correct 186 ms 14756 KB Output is correct
65 Correct 182 ms 14768 KB Output is correct
66 Correct 195 ms 14928 KB Output is correct
67 Correct 214 ms 14928 KB Output is correct
68 Correct 156 ms 14772 KB Output is correct
69 Correct 146 ms 14760 KB Output is correct
70 Correct 145 ms 14932 KB Output is correct