이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#include "wiring.h"
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const ll nmax=2e5+50;
const int mod=1e9+7;
using namespace std;
int n,m,i,j,t,g;
ll x,y,cur;
vector<ll>ans[nmax],mn[nmax],suf[nmax],bst[nmax],gr[nmax],sf[nmax];
vector<pair<ll,int> >a;
ll min_total_length(vector<int>R,vector<int>B)
{
n=R.size(),m=B.size();
for(i=1;i<=n;i++)
{
x=R[i-1];
a.pb(mkp(x,0));
}
for(i=1;i<=m;i++)
{
x=B[i-1];
a.pb(mkp(x,1));
}
sort(a.begin(),a.end());
for(i=0;i<n+m;i++)
{
if(!i || a[i-1].sc!=a[i].sc)g++;
gr[g].pb(a[i].fr);
}
for(i=1;i<=g;i++)
{
for(j=gr[i].size()-1,t=0;j>=0;j--,t++)
{
suf[i].pb(0);
ans[i].pb(0);
bst[i].pb(0);
mn[i].pb(0);
sf[i].pb(0);
suf[i][t]=gr[i].back()-gr[i][j];
if(t)suf[i][t]+=suf[i][t-1];
}
if(i>2)
{
x=0;
for(j=0;j<gr[i].size();j++)
{
x+=gr[i][j]-gr[i][0];
y=1LL*(j+1)*(gr[i][0]-gr[i-1].back());
cur=x+y+bst[i-1][min(j,(int)gr[i-1].size()-1)];
if(j+1<gr[i-1].size())cur=min(cur,x+mn[i-1][j+1]);
ans[i][j]=cur;
}
}
else if(i==2)
{
x=0;
for(j=0;j<gr[i].size();j++)
{
x+=gr[i][j]-gr[i][0];
y=1LL*max((int)gr[1].size(),j+1)*(gr[2][0]-gr[1].back());
ans[i][j]=x+y+suf[1].back();
}
}
if(i<g && i>1)
{
for(j=gr[i].size()-1;j>=0;j--)
{
sf[i][j]=gr[i+1][0]-gr[i][j];
if(j+1<gr[i].size())sf[i][j]+=sf[i][j+1];
}
cur=llinf;
for(j=0;j<gr[i].size();j++)
{
if(i==2 && !j)continue;
if(j)cur=min(cur,ans[i][j-1]+sf[i][j]);
else cur=min(cur,ans[i-1].back()+sf[i][j]);
x=0;
if(j+1<gr[i].size())x=sf[i][j+1];
ans[i][j]=min(ans[i][j],cur-x);
}
for(j=gr[i].size()-1,t=0;j>=0;j--,t++)
{
bst[i][t]=suf[i][t];
if(j)bst[i][t]+=ans[i][j-1];
else
{
if(i==2)bst[i][t]+=ans[i][0];
else bst[i][t]+=ans[i-1].back();
}
if(t)bst[i][t]=min(bst[i][t],bst[i][t-1]);
mn[i][j]=suf[i][j]+1LL*(j+1)*(gr[i+1][0]-gr[i].back());
if(t)mn[i][j]+=ans[i][t-1];
else
{
if(i==2)mn[i][j]+=ans[i][0];
else mn[i][j]+=ans[i-1].back();
}
if(j<gr[i].size()-1)mn[i][j]=min(mn[i][j],mn[i][j+1]);
}
}
}
return ans[g].back();
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("O3")
wiring.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("unroll-loops")
wiring.cpp: In function 'll min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:60:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0;j<gr[i].size();j++)
~^~~~~~~~~~~~~
wiring.cpp:65:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(j+1<gr[i-1].size())cur=min(cur,x+mn[i-1][j+1]);
~~~^~~~~~~~~~~~~~~
wiring.cpp:72:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0;j<gr[i].size();j++)
~^~~~~~~~~~~~~
wiring.cpp:84:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(j+1<gr[i].size())sf[i][j]+=sf[i][j+1];
~~~^~~~~~~~~~~~~
wiring.cpp:87:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0;j<gr[i].size();j++)
~^~~~~~~~~~~~~
wiring.cpp:93:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(j+1<gr[i].size())x=sf[i][j+1];
~~~^~~~~~~~~~~~~
wiring.cpp:113:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(j<gr[i].size()-1)mn[i][j]=min(mn[i][j],mn[i][j+1]);
~^~~~~~~~~~~~~~~
# | 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... |