# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
240565 | arnold518 | Feast (NOI19_feast) | C++14 | 175 ms | 15224 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 3e5;
const ll INF = 1e13;
int N, K;
ll A[MAXN+10];
pll dp1[MAXN+10], dp2[MAXN+10];
ll ans;
int solve(ll lambda)
{
int i, j;
dp1[0]={-INF, 0};
dp2[0]={0, 0};
for(i=1; i<=N; i++)
{
if(dp1[i-1].first>dp2[i-1].first-lambda) dp1[i]={dp1[i-1].first+A[i]*2, dp1[i-1].second};
else dp1[i]={dp2[i-1].first-lambda+A[i]*2, dp2[i-1].second+1};
dp2[i]=max(dp1[i-1], dp2[i-1]);
}
ans=max(dp1[N].first, dp2[N].first);
if(dp1[N].first>dp2[N].first) return dp1[N].second;
else return dp2[N].second;
}
int main()
{
int i, j;
scanf("%d%d", &N, &K);
for(i=1; i<=N; i++) scanf("%lld", &A[i]);
ll lo=0, hi=INF;
while(lo+1<hi)
{
ll mid=lo+hi>>1;
if(solve(mid*2+1)>=K) lo=mid;
else hi=mid;
}
solve(lo*2);
printf("%lld\n", ans/2+lo*K);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |