답안 #84396

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
84396 2018-11-15T06:19:42 Z wzy Cipele (COCI18_cipele) C++11
90 / 90
925 ms 16396 KB
#include <bits/stdc++.h>
using namespace std;

int n , m;
vector<int> small, big;

int32_t main(){
	scanf("%d%d" , &n , &m);
	small.resize(n) , big.resize(m);
	for(int i = 0 ; i < n ;i ++){
		scanf("%d" , &small[i]);
	}
	for(int i = 0 ; i < m ; i++){
		scanf("%d" , &big[i]);
	}
	sort(small.begin() , small.end());
	sort(big.begin() , big.end());
	int l = 0 , r = 1000000000;
	if(small.size() > big.size()) swap(n,m) , swap(small , big);
	int ansj = -1;
	while(l<=r){
		int mid = (l+r)/2;
		int can = true;
		multiset<int> mt;
		for(int i = 0 ; i < big.size() ; i++) mt.insert(big[i]);
		for(int i = 0 ; i < small.size() ; i++){
			multiset<int>::iterator it = mt.lower_bound(small[i] - mid);
			if(it == mt.end()){
				can = false;
				break;
			}
			int u = *it;
			if(abs(u - small[i]) <= mid){
				mt.erase(it);
				continue;
			} 
			else{
				can = false;
				break;
			}
		}
		if(can){
			ansj = mid;
			r = mid - 1;
		}
		else l = mid + 1;
	}
	printf("%d\n" , ansj);
}

Compilation message

cipele.cpp: In function 'int32_t main()':
cipele.cpp:25:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0 ; i < big.size() ; i++) mt.insert(big[i]);
                   ~~^~~~~~~~~~~~
cipele.cpp:26:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0 ; i < small.size() ; i++){
                   ~~^~~~~~~~~~~~~~
cipele.cpp:8:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d" , &n , &m);
  ~~~~~^~~~~~~~~~~~~~~~~~
cipele.cpp:11:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d" , &small[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~
cipele.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d" , &big[i]);
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 833 ms 7416 KB Output is correct
2 Correct 914 ms 9160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 925 ms 11344 KB Output is correct
2 Correct 887 ms 12552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 12552 KB Output is correct
2 Correct 21 ms 12552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 12552 KB Output is correct
2 Correct 20 ms 12552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 12552 KB Output is correct
2 Correct 20 ms 12552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 12552 KB Output is correct
2 Correct 20 ms 12552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 12552 KB Output is correct
2 Correct 22 ms 12552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 679 ms 12552 KB Output is correct
2 Correct 321 ms 12552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 561 ms 12764 KB Output is correct
2 Correct 598 ms 13504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 561 ms 15140 KB Output is correct
2 Correct 643 ms 16396 KB Output is correct