답안 #1017491

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017491 2024-07-09T08:22:42 Z vjudge1 Feast (NOI19_feast) C++17
100 / 100
97 ms 7508 KB
#include <bits/stdc++.h>
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define pb push_back
using namespace std;
const ll N=3e5+9;
const ll mod=1e9+7;
    ll t,n,k,i,m,x,a[N],tot[N],q,l,b[N],c[N],mu[N],sl=0,xor_basis[64],len=0,r;
ll dp[N][2];
ii check(ll pen)
{
    dp[0][1]=-pen;
    dp[0][0]=0;
    ll res=0;
    ll cnt=0;
    for(i=1;i<=n;i++)
    {
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
        dp[i][1]=max(dp[i-1][0]-pen,dp[i-1][1])+a[i];
        res=max(res,dp[i][1]);
    }
    bool op=0;
    ll tot=res;
    if(res==0) return {0,0};
    for(i=n;i>0;i--)
    if(res==dp[i][1])
    {
        res-=a[i];
        if(!op){ cnt++;}
        //if(res==0) break;
        op=1;
    }
    else{if(op)res+=pen; op=0;}
        return {tot+pen*cnt,cnt};
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
cin>>n>>k;
for(i=1;i<=n;i++)
    cin>>a[i];
ll l=0,r=1e18,kq=0;
while(l<=r)
{
    ll mid=(l+r)/2;
    ii ans=check(mid);
  //  cout<<mid<<" "<<ans.se<<'\n';
    if(ans.se<=k){
            if(ans.se>0)
        kq=max(kq,ans.fi);
        r=mid-1;
    }
    else l=mid+1;
}
cout<<kq;
}
/*
6 2
1 2 3 -10 5 6

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 7248 KB Output is correct
2 Correct 69 ms 7260 KB Output is correct
3 Correct 78 ms 7252 KB Output is correct
4 Correct 68 ms 7260 KB Output is correct
5 Correct 69 ms 7332 KB Output is correct
6 Correct 71 ms 7156 KB Output is correct
7 Correct 67 ms 7260 KB Output is correct
8 Correct 69 ms 7252 KB Output is correct
9 Correct 67 ms 7252 KB Output is correct
10 Correct 69 ms 7504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 7256 KB Output is correct
2 Correct 59 ms 7260 KB Output is correct
3 Correct 61 ms 7260 KB Output is correct
4 Correct 59 ms 7372 KB Output is correct
5 Correct 76 ms 7508 KB Output is correct
6 Correct 60 ms 7296 KB Output is correct
7 Correct 60 ms 7480 KB Output is correct
8 Correct 72 ms 7412 KB Output is correct
9 Correct 69 ms 7252 KB Output is correct
10 Correct 63 ms 7504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 7256 KB Output is correct
2 Correct 70 ms 7324 KB Output is correct
3 Correct 75 ms 7372 KB Output is correct
4 Correct 71 ms 7324 KB Output is correct
5 Correct 72 ms 7388 KB Output is correct
6 Correct 72 ms 7256 KB Output is correct
7 Correct 73 ms 7248 KB Output is correct
8 Correct 72 ms 7308 KB Output is correct
9 Correct 73 ms 7316 KB Output is correct
10 Correct 72 ms 7248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 7248 KB Output is correct
2 Correct 69 ms 7260 KB Output is correct
3 Correct 78 ms 7252 KB Output is correct
4 Correct 68 ms 7260 KB Output is correct
5 Correct 69 ms 7332 KB Output is correct
6 Correct 71 ms 7156 KB Output is correct
7 Correct 67 ms 7260 KB Output is correct
8 Correct 69 ms 7252 KB Output is correct
9 Correct 67 ms 7252 KB Output is correct
10 Correct 69 ms 7504 KB Output is correct
11 Correct 58 ms 7256 KB Output is correct
12 Correct 59 ms 7260 KB Output is correct
13 Correct 61 ms 7260 KB Output is correct
14 Correct 59 ms 7372 KB Output is correct
15 Correct 76 ms 7508 KB Output is correct
16 Correct 60 ms 7296 KB Output is correct
17 Correct 60 ms 7480 KB Output is correct
18 Correct 72 ms 7412 KB Output is correct
19 Correct 69 ms 7252 KB Output is correct
20 Correct 63 ms 7504 KB Output is correct
21 Correct 72 ms 7256 KB Output is correct
22 Correct 70 ms 7324 KB Output is correct
23 Correct 75 ms 7372 KB Output is correct
24 Correct 71 ms 7324 KB Output is correct
25 Correct 72 ms 7388 KB Output is correct
26 Correct 72 ms 7256 KB Output is correct
27 Correct 73 ms 7248 KB Output is correct
28 Correct 72 ms 7308 KB Output is correct
29 Correct 73 ms 7316 KB Output is correct
30 Correct 72 ms 7248 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 344 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 2 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 93 ms 7304 KB Output is correct
62 Correct 97 ms 7488 KB Output is correct
63 Correct 73 ms 7256 KB Output is correct
64 Correct 91 ms 7256 KB Output is correct
65 Correct 85 ms 7260 KB Output is correct
66 Correct 86 ms 7252 KB Output is correct
67 Correct 89 ms 7260 KB Output is correct
68 Correct 72 ms 7260 KB Output is correct
69 Correct 69 ms 7152 KB Output is correct
70 Correct 79 ms 7256 KB Output is correct