Submission #623335

#TimeUsernameProblemLanguageResultExecution timeMemory
623335Dremix10Wiring (IOI17_wiring)C++17
0 / 100
1 ms468 KiB
#include "wiring.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pi; typedef pair<ll,ll> pl; #define F first #define S second #define all(x) (x).begin(),(x).end() #ifdef dremix #define p(x) cerr<<#x<<" = "<<x<<endl; #define p2(x,y) cerr<<#x<<" , "<<#y<<" = "<<x<<" , "<<y<<endl; #define pp(x) cerr<<#x<<" = "<<x.F<<"-"<<x.S<<endl; #define pv(x) cerr<<#x<<" = {";for(auto v : x)cerr<<v<<", ";cerr<<"}"<<endl; #define ppv(x) cerr<<#x<<" = {";for(auto v : x)cerr<<v.F<<"-"<<v.S<<", ";cerr<<"}"<<endl; #else #define p(x) {} #define p2(x,y) {} #define pp(x) {} #define pv(x) {} #define ppv(x) {} #endif const int N = 3e5+5; const int MOD = 1e9+7; const ll INF = 1e18+5; long long min_total_length(std::vector<int> r, std::vector<int> b) { int n = r.size(); int m = b.size(); int i,j,k; ll ans = INF; for(k=max(n,m);k <= n+m ;k++){ ll res = 0; p2(n,m) p2(k,n+m) if(k > n+m)break; p((k > n+m)) p2(k,n+m) int duos = n+m-k; p(duos) if(duos < 0)break; p((duos < 0)) bool vr[n] = {}; bool vb[m] = {}; while(duos--){ pi idx = {-1,-1}; int mini = MOD; for(i=0;i<n;i++){ if(vr[i])continue; for(j=0;j<m;j++){ if(vb[j])continue; if(mini > abs(r[i] - b[j])){ mini = abs(r[i] - b[j]); idx = {i,j}; } } } pv(vr) pv(vb) p2(duos,k) assert(idx.F != -1); res += mini; vr[idx.F] = true; vb[idx.S] = true; } for(i=0;i<n;i++){ if(vr[i])continue; int idx = 0; for(j=1;j<m;j++){ if(abs(r[i] - b[idx]) > abs(r[i] - b[j])) idx = j; } res += abs(r[i] - b[idx]); vr[i] = true; } for(i=0;i<m;i++){ if(vb[i])continue; int idx = 0; for(j=1;j<n;j++){ if(abs(r[idx] - b[i]) > abs(r[j] - b[i])) idx = j; } res += abs(r[idx] - b[i]); vb[i] = true; } ans = min(ans,res); } }

Compilation message (stderr)

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:95:1: warning: control reaches end of non-void function [-Wreturn-type]
   95 | }
      | ^
#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...