| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1017287 | vjudge1 | Feast (NOI19_feast) | C++17 | 115 ms | 12368 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define double long double
#define pb push_back
#define endl '\n'
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define setmin(x,y) x=min((x),(y))
#define setmax(x,y) x=max((x),(y))
#define fi first
#define se second
mt19937 hdp(69420);
int rand(int l,int r){return l+((hdp()%(r-l+1))+r-l+1)%(r-l+1);}
const int N = 3e5 + 5;
const int mod = 1e9 + 7;
const int SQ = 450;
const int inf = 1e17;
const int L = 40;
int n,k,a[N];
pair<int,int> dp[N][2];
pair<int,int> solve(int lambda)
{
for(int i=1;i<=n;i++)
{
dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
dp[i][1]=max(make_pair(dp[i-1][0].fi+a[i]-lambda,dp[i-1][0].se+1),make_pair(dp[i-1][1].fi+a[i],dp[i-1][1].se));
}
return max(dp[n][0],dp[n][1]);
}
signed main()
{
fastIO
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
dp[0][1]={-inf,0};
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i];
int l=0,r=inf;
while(l<r-1)
{
int m=l+r>>1;
auto res=solve(m);
if(res.se>k) l=m;
else r=m;
}
auto res=solve(r);
cout<<res.fi+res.se*r;
}
컴파일 시 표준 에러 (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... | ||||
