답안 #1017629

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017629 2024-07-09T09:14:42 Z vjudge1 Feast (NOI19_feast) C++17
0 / 100
1000 ms 2904 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define ll 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<ll,int> a,pair<ll,int>b){
    return make_pair(a.F,-1 * a.S) > make_pair(b.F, -1 * b.S);
}
bool operator<(pair<ll,int> a,pair<ll,int>b){
    return make_pair(a.F,-1 * a.S) < make_pair(b.F, -1 * b.S);
}
int n,k;
int a[mxN];
pair<ll,int> dp[2][2];
pair<ll,int> num;
int ans;
bool solve(int lam){
    // cout<<lam<<'\n';
    for(int i = 0;i <= 1;i++){
        dp[i][0] = make_pair(0,0);
        dp[i][1] = make_pair(0,0);
    }
    for(int i = 1;i <= n;i++){
        // cout<<(i & 1)<<' '<<(~i & 1)<<'\n';
        dp[(i & 1)][0] = max(dp[(~i & 1)][0],dp[(~i & 1)][1]);
        dp[(i & 1)][1] = make_pair(dp[(~i & 1)][0].F + a[i] - lam,dp[~i & 1][0].S + 1);
        if(i > 1) dp[(i & 1)][1] = max(dp[(i & 1)][1],make_pair(dp[~i & 1][1].F + a[i],dp[~i & 1][1].S));
        // cout<<dp[(i & 1)][0].F<<' '<<dp[(i & 1)][0].S<<' '<<dp[(i & 1)][1].F<<' '<<dp[(i & 1)][1].S<<'\n';
    }
    num = max(dp[n & 1][0],dp[n & 1][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];
    ll 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:42:23: warning: unused variable 'md' [-Wunused-variable]
   42 |     ll l = 0,r = 1e16,md;
      |                       ^~
feast.cpp:43:9: warning: unused variable 'binit' [-Wunused-variable]
   43 |     int binit = 60;
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 98 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 2652 KB Output is correct
2 Correct 64 ms 2652 KB Output is correct
3 Correct 67 ms 2652 KB Output is correct
4 Correct 65 ms 2648 KB Output is correct
5 Incorrect 97 ms 2904 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1024 ms 2664 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1075 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1075 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1075 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 98 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -