이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
#define sz(a) ((int)(a.size()))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
vector<ll> v;
int n;
bool check1(pll a,pll b,int c){
return a.fs*c+a.sc>b.fs*c+b.sc;
}
bool check2(pll a,pll b,pll c){
return (b.sc-a.sc)*(b.fs-c.fs)<=(b.sc-c.sc)*(b.fs-a.fs);
}
ll get(ll p,bool x){
vector<pair<pll,int> > dq;
vector<pll> dp(n);
int l=0;
dq.push_back({{1-v[0],(1-v[0])*(1-v[0])},0});
for(int i=0;i<n;i++){
while(sz(dq)-l>1 && check1(dq[l].fs,dq[l+1].fs,2*i)){
l++;
}
dp[i].fs=2ll*i*dq[l].fs.fs+dq[l].fs.sc+1ll*i*i+p;
dp[i].sc=dq[l].sc+1;
int xf=0;
if(i>=v[i+1]){
xf=-(i-v[i+1]+1)*(i-v[i+1]+1);
}
ll a=(1-v[i+1]),b=dp[i].fs+(1ll*(1-v[i+1])*(1-v[i+1]))+xf;
while(sz(dq)-l>1 && check2(dq[sz(dq)-1].fs,dq[sz(dq)-2].fs,{a,b})){
dq.pop_back();
}
dq.push_back({{a,b},dp[i].sc});
}
if(x==0){
return dp[n-1].sc;
}
else{
return dp[n-1].fs;
}
}
ll take_photos(int N, int M, int k, vector<int> R, vector<int> C) {
n=M;
int m=N;
v.resize(n+1,n);
for(int i=0;i<m;i++){
if(R[i]<C[i]){
swap(R[i],C[i]);
}
v[R[i]]=min(v[R[i]],(ll)C[i]);
}
for(int i=n-2;i>=0;i--){
v[i]=min(v[i],v[i+1]);
}
ll l=0,r=2e14;
while(r>l){
ll mid=(l+r)/2;
if(get(mid,0)<=k){
r=mid;
}
else{
l=mid+1;
}
}
return get(l,1)-l*k;
}
# | 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... |