Submission #600258

# Submission time Handle Problem Language Result Execution time Memory
600258 2022-07-20T15:42:29 Z StrawHatWess Wiring (IOI17_wiring) C++17
0 / 100
1000 ms 6092 KB
#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
*/

Compilation message

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 time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '14340', found: '14560'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Execution timed out 1080 ms 4668 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Execution timed out 1077 ms 6092 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1084 ms 5408 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '14340', found: '14560'
3 Halted 0 ms 0 KB -