제출 #738396

#제출 시각아이디문제언어결과실행 시간메모리
738396Elvin_Fritl전선 연결 (IOI17_wiring)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #include "wiring.h" long long min_total_length(vector<int> r, vector<int> b){ set<int>s,s1; vector<int>chek((int)b.size() + (int)r.size(),0); for(int i=0;i<(int)r.size();i++){ s.insert(r[i]); } long long res=0; for(int i=0;i<(int)b.size();i++){ s1.insert(b[i]); auto it=s.upper_bound(b[i]); auto it2=it; if(it!=s.begin()){ it2--; } int tmp1=abs(*it - b[i]); int tmp2=abs(*it2 - b[i]); if(tmp1>tmp2){ chek[*it2]=1; res+=tmp2; } else if(tmp1<tmp2){ chek[*it]=1; res+=tmp1; } else{ if(chek[*it]==1){ chek[*it2]=1; res+=tmp2; } else{ chek[*it]=1; res+=tmp1; } } } for(int i=0;i<(int)r.size();i++){ if(chek[r[i]]==0){ auto it=s1.upper_bound(r[i]); auto it2=it; if(it!=s1.begin()){ it2--; } int tmp1=abs(*it - r[i]); int tmp2=abs(*it2 - r[i]); if(tmp1>tmp2){ chek[*it2]=1; res+=tmp2; } else if(tmp1<tmp2){ chek[*it]=1; res+=tmp1; } else{ if(chek[*it]==1){ chek[*it2]=1; res+=tmp2; } else{ chek[*it]=1; res+=tmp1; } } } } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...