제출 #640428

#제출 시각아이디문제언어결과실행 시간메모리
640428ggoh전선 연결 (IOI17_wiring)C++14
0 / 100
1083 ms7668 KiB
#include "wiring.h" #include<bits/stdc++.h> using namespace std; #define sz(v) ((int)(v).size()) typedef long long lint; typedef pair<int,int> pii; lint min_total_length(vector<int> r, vector<int> b) { if(sz(r)<sz(b))swap(r,b); int n=sz(r),m=sz(b); int minV,mini,minind; set<int>V[100002]; for(int i=0;i<n;i++) { mini=1e9+1; minind=-1; for(int j=0;j<m;j++) { if(abs(r[i]-b[j])<mini) { mini=abs(r[i]-b[j]); minind=j; } } V[minind].insert(i); } int st[100002],sz=0; for(int i=0;i<m;i++) { if(!sz(V[i]))st[sz++]=i; } for(int i=0;i<sz;i++) { mini=1e9+1; minind=-1; minV=-1; for(int j=0;j<m;j++) { if(sz(V[j])>1) { for(auto &k:V[j]) { if(abs(r[k]-b[st[i]])-abs(r[k]-b[j])<mini) { mini=abs(r[k]-b[st[i]])-abs(r[k]-b[j]); minind=k;minV=j; } } } } V[st[i]].insert(minind); V[minV].erase(minind); } lint ans=0; for(int i=0;i<m;i++) { for(auto &k:V[i]) { ans+=abs(r[k]-b[i]); } } return ans; }
#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...