답안 #710641

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
710641 2023-03-15T13:04:09 Z Warinchai Cipele (COCI18_cipele) C++14
90 / 90
98 ms 2556 KB
#include<bits/stdc++.h>
using namespace std;
vector<long long>l;
vector<long long>r;
int check(long long mid){
	int j=0;
	for(int i=0;i<l.size();i++){
		while(abs(l[i]-r[j])>mid){
			j++;
			if(j>r.size()-1){
				break;
			}
		}
		if(j>r.size()-1){
			break;
		}
		if(i==l.size()-1){
			return 1;
		}
		j++;
		if(j>r.size()-1){
			break;
		}
	}
	return 0;
}
int check2(long long mid){
	int j=0;
	for(int i=0;i<r.size();i++){
		while(abs(r[i]-l[j])>mid){
			j++;
			if(j>l.size()-1){
				break;
			}
		}
		if(j>l.size()-1){
			break;
		}
		if(i==r.size()-1){
			return 1;
		}
		j++;
		if(j>l.size()-1){
			break;
		}
	}
	return 0;
}
int main(){
	int a,b;
	cin>>a>>b;
	for(int i=0;i<a;i++){
		int x;
		cin>>x;
		l.push_back(x);
	}
	for(int i=0;i<b;i++){
		int x;
		cin>>x;
		r.push_back(x);
	}
	sort(l.begin(),l.end());
	sort(r.begin(),r.end());
	long long st=0,en=10e9,ans=0,mid;
	while(st<=en){
		mid=(st+en)/2;
		if(l.size()>r.size()){
			if(check2(mid)){
				en=mid-1;
				ans=mid;
			}else{
				st=mid+1;
			}	
		}else{
			if(check(mid)){
				en=mid-1;
				ans=mid;
			}else{
				st=mid+1;
			}	
		}
	}
	cout<<ans;
}

Compilation message

cipele.cpp: In function 'int check(long long int)':
cipele.cpp:7:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |  for(int i=0;i<l.size();i++){
      |              ~^~~~~~~~~
cipele.cpp:10:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |    if(j>r.size()-1){
      |       ~^~~~~~~~~~~
cipele.cpp:14:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |   if(j>r.size()-1){
      |      ~^~~~~~~~~~~
cipele.cpp:17:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |   if(i==l.size()-1){
      |      ~^~~~~~~~~~~~
cipele.cpp:21:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   if(j>r.size()-1){
      |      ~^~~~~~~~~~~
cipele.cpp: In function 'int check2(long long int)':
cipele.cpp:29:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for(int i=0;i<r.size();i++){
      |              ~^~~~~~~~~
cipele.cpp:32:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |    if(j>l.size()-1){
      |       ~^~~~~~~~~~~
cipele.cpp:36:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   if(j>l.size()-1){
      |      ~^~~~~~~~~~~
cipele.cpp:39:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   if(i==r.size()-1){
      |      ~^~~~~~~~~~~~
cipele.cpp:43:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   if(j>l.size()-1){
      |      ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 2496 KB Output is correct
2 Correct 98 ms 2496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 2496 KB Output is correct
2 Correct 90 ms 2556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 6 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 6 ms 400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 392 KB Output is correct
2 Correct 7 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 340 KB Output is correct
2 Correct 5 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 340 KB Output is correct
2 Correct 5 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 2340 KB Output is correct
2 Correct 54 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 2456 KB Output is correct
2 Correct 49 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 2268 KB Output is correct
2 Correct 74 ms 2404 KB Output is correct