이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define maxn 100005
#define II pair <ll,ll>
#define III pair <ll,II>
#define IV pair <vector <int>,vector <int> >
#define IDB pair <db,int>
#define TII pair <treap*,treap*>
#define fst first
#define snd second
#define BIT(x,i) ((x>>i)&1)
#define pi acos(-1)
#define to_radian(x) (x*pi/180.0)
#define to_degree(x) (x*180.0/pi)
#define Log(x) (31-__builtin_clz((int)x))
#define LogLL(x) (63-__builtin_clzll((ll)x)
#include "meetings.h"
using namespace std;
const ll oo=round(1e18);
ll a[maxn],i,j,q,n,up[5005][5005],down[5005][5005];
vector <ll> minimum_costs(vector <int> h,vector <int> L,vector <int> R)
{
for(int x:h) a[++n]=x;
q=L.size();
for(i=0;i<q;i++) L[i]++,R[i]++;
vector <ll> res(q);
if(n<=5000 && q<=5000)
{
for(i=1;i<=n;i++)
{
ll ma=0;
for(j=i;j>=1;j--)
{
ma=max(ma,a[j]);
down[i][j]=down[i][j+1]+ma;
}
ma=0;
for(j=i;j<=n;j++)
{
ma=max(ma,a[j]);
up[i][j]=up[i][j-1]+ma;
}
}
for(i=0;i<q;i++)
{
int l=L[i],r=R[i];
res[i]=oo;
for(int u=l;u<=r;u++)
res[i]=min(res[i],down[u][l]+up[u][r]-a[u]);
}
}
return res;
}
/*
int main()
{
freopen("meetings.inp","r",stdin);
freopen("meetings.out","w",stdout);
vector <int> a,L,R;
int k,n,l,r;
cin>>n;
for(int i=1;i<=n;i++) cin>>k,a.push_back(k);
while(cin>>l>>r) L.push_back(l),R.push_back(r);
vector <ll> res=minimum_costs(a,L,R);
for(int x:res) cout<<x<<'\n';
}
*/
# | 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... |