제출 #600258

#제출 시각아이디문제언어결과실행 시간메모리
600258StrawHatWessWiring (IOI17_wiring)C++17
0 / 100
1084 ms6092 KiB
#include "wiring.h"

#include <bits/stdc++.h>
using namespace std; 

typedef long long ll; 
#define FOR(i,a,b) for(int i=a; i<b; i++)
typedef vector<int>vi; 
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x) 

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const ll INF=1e18; 

//------------------------------------------

int N, M;
vi r,b; 

ll dist(int i, int j){return abs(b[j]-r[i]);}

ll min_total_length(vi r, vi b) {
	::r=r; ::b=b;
	N=sz(r), M=sz(b);

	vector<ll> reqr(N,INF), reqb(M,INF);
	FOR(i,0,N) FOR(j,0,M) ckmin(reqr[i],dist(i,j)), ckmin(reqb[j],dist(i,j)); ; 

	ll ans=0; 
	FOR(i,0,N){
		ll dif=-1; int idx; 
		FOR(j,0,M) if(ckmax(dif,reqr[i]+reqb[j]-dist(i,j))) idx=j;

		ans+=dist(i,idx); 
		reqr[i]=0; reqb[idx]=0; 
	}
	FOR(j,0,M) if(reqb[j]){
		ll dif=-1; int idx; 
		FOR(i,0,N) if(ckmax(dif,reqr[i]+reqb[j]-dist(i,j))) idx=i;

		ans+=dist(idx,j); 
	}
	return ans; 

}

/*
4 5
1 2 3 7
0 4 5 9 10


10
*/

컴파일 시 표준 에러 (stderr) 메시지

wiring.cpp: In function 'll min_total_length(vi, vi)':
wiring.cpp:23:42: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   23 | ll dist(int i, int j){return abs(b[j]-r[i]);}
      |                                          ^
wiring.cpp:41:18: note: 'idx' was declared here
   41 |   ll dif=-1; int idx;
      |                  ^~~
wiring.cpp:23:37: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   23 | ll dist(int i, int j){return abs(b[j]-r[i]);}
      |                                     ^
wiring.cpp:34:18: note: 'idx' was declared here
   34 |   ll dif=-1; int idx;
      |                  ^~~
#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...