이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include<bits/stdc++.h>
using namespace std;
const long long maxn=200000+10,lg=19,kaf=(1<<lg);
long long dp[maxn],inf=1e16,vas[maxn];
long long n,m,ps[maxn],suf[maxn],ghabl[maxn],bad[maxn];
vector<long long>allind;
struct segment{
long long seg[(1<<(lg+1))];
segment(){
for(int i=0;i<(1<<(lg+1));i++){
seg[i]=inf;
}
}
void ins(long long w,int ind){
ind+=kaf;
while(ind>0){
seg[ind]=min(seg[ind],w);
ind>>=1;
}
return ;
}
long long pors(int i,int l,int r,int tl,int tr){
if(l>r||l>tr||r<tl||tl>tr){
return inf;
}
if(l>=tl&&r<=tr){
return seg[i];
}
int m=(l+r)>>1;
return min(pors((i<<1),l,m,tl,tr),pors((i<<1)^1,m+1,r,tl,tr));
}
}seg1,seg2;
long long min_total_length(std::vector<int> r, std::vector<int> b) {
n=(long long)r.size();
m=(long long)b.size();
allind.push_back(-1);
for(auto x:r){
allind.push_back(x);
}
for(auto x:b){
allind.push_back(x);
}
sort(allind.begin(),allind.end());
allind.resize(unique(allind.begin(),allind.end())-allind.begin());
for(long long i=0;i<n;i++){
r[i]=lower_bound(allind.begin(),allind.end(),r[i])-allind.begin();
vas[r[i]]=1;
}
for(long long i=0;i<m;i++){
b[i]=lower_bound(allind.begin(),allind.end(),b[i])-allind.begin();
vas[b[i]]=2;
}
for(long long i=1;i<maxn;i++){
dp[i]=inf;
if((int)allind.size()>i){
ps[i]=ps[i-1]+allind[i];
if(vas[i]!=vas[i-1]){
ghabl[i]=i;
}else{
ghabl[i]=ghabl[i-1];
}
}
}
for(int i=(int)allind.size()-1;i>=1;i--){
suf[i]=suf[i+1]+allind[i];
if(vas[i]!=vas[i+1]){
bad[i]=i;
}else{
bad[i]=bad[i+1];
}
}
dp[0]=0;
long long sz=(long long)allind.size();
allind.push_back(0);
for(long long i=1;i<sz;i++){
long long av=allind[i],unnow=0,last=i,bar=0,akh;
long long ted1=i-ghabl[i]+1;
long long f=(ps[i]-ps[ghabl[i]-1])-(allind[ghabl[i]]*(ted1));
long long z=ghabl[ghabl[i]-1];
if(ghabl[i]!=1){
long long tagh=ghabl[i]-ted1;
tagh=max(tagh,z);
dp[i]=min(dp[i],seg1.pors(1,0,kaf-1,tagh,ghabl[i]-1)+f+ted1*(allind[ghabl[i]]-allind[ghabl[i]-1]));
dp[i]=min(dp[i],seg2.pors(1,0,kaf-1,z,tagh-1)+f);
//cout<<i<<" "<<tagh<<" "<<z<<" "<<ghabl[i]<<" "<<dp[i]<<" "<<seg1.pors(1,0,kaf-1,tagh,ghabl[i]-1)<<" "<<seg2.pors(1,0,kaf-1,z,tagh-1)<<" "<<ted1<<endl;
}
/* for(long long j=i-1;j>=1;j--){
if(vas[j]==vas[i]&&vas[j]!=vas[j+1]){
break;
}
if(vas[j]==vas[i]){
last=j;
unnow+=av;
av=allind[j];
}else{
bar+=allind[j];
akh=allind[last-1];
long long ted2=(last-1)-j+1;
//dp[i]=min(dp[i],min(dp[j],dp[j-1])+(ps[i]-ps[last-1])-(allind[last]*ted1)-(suf[j]-suf[last])+(allind[last-1]*ted2)+max(ted1,ted2)*(allind[last]-allind[last-1]));
//dp[i]=min(dp[i],seg.pors(1,0,kaf-1,j,j)+f+max(ted1,ted2)*(allind[last]-allind[last-1]));
if(ted1<ted2){
dp[i]=min(dp[i],seg2.pors(1,0,kaf-1,j,j)+f);
}else{
dp[i]=min(dp[i],seg1.pors(1,0,kaf-1,j,j)+f+ted1*(allind[ghabl[i]]-allind[ghabl[i]-1]));
}
}
}*/
if(bad[i]+1>=(int)allind.size()){
continue;
}
long long ted2=bad[i]-i+1;
seg1.ins(min(dp[i],dp[i-1])-(suf[i]-suf[bad[i]+1])+(allind[bad[i]]*ted2),i);
seg2.ins(min(dp[i],dp[i-1])-(suf[i]-suf[bad[i]+1])+(allind[bad[i]]*ted2)+ted2*(allind[bad[i]+1]-allind[bad[i]]),i);
// cout<<i<<" "<<dp[i]<<" "<<vas[i]<<endl;
}
return dp[sz-1];
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:79:13: warning: unused variable 'av' [-Wunused-variable]
79 | long long av=allind[i],unnow=0,last=i,bar=0,akh;
| ^~
wiring.cpp:79:26: warning: unused variable 'unnow' [-Wunused-variable]
79 | long long av=allind[i],unnow=0,last=i,bar=0,akh;
| ^~~~~
wiring.cpp:79:34: warning: unused variable 'last' [-Wunused-variable]
79 | long long av=allind[i],unnow=0,last=i,bar=0,akh;
| ^~~~
wiring.cpp:79:41: warning: unused variable 'bar' [-Wunused-variable]
79 | long long av=allind[i],unnow=0,last=i,bar=0,akh;
| ^~~
wiring.cpp:79:47: warning: unused variable 'akh' [-Wunused-variable]
79 | long long av=allind[i],unnow=0,last=i,bar=0,akh;
| ^~~
# | 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... |