답안 #160663

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
160663 2019-10-29T08:08:26 Z mraron Cipele (COCI18_cipele) C++14
90 / 90
93 ms 6864 KB
/*
ID: noszaly1
TASK: {TASK}
LANG: C++11               
*/

//Noszály Áron 10o Debreceni Fazekas Mihály Gimnázium

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}
#define int ll
main() {
	IO;
	int n,m;
	cin>>n>>m;
	vector<int> a(n), b(m);
	for(int i=0;i<n;++i) {
		cin>>a[i];
	}
	
	for(int i=0;i<m;++i) {
		cin>>b[i];
	}
	
	sort(all(a));
	sort(all(b));
	
	if(n==m) {
		int ans=0;
		for(int i=0;i<n;++i) ans=max(ans, abs(a[i]-b[i]));
		cout<<ans<<"\n";
		return 0;
	}
	
	if(n>m) {
		swap(n,m);
		a.swap(b);
	}
	
	int curr=1000000000;
	for(int i=40;i>=0;i--) {
		int akt=curr-(1LL<<i);
		if(akt<0) continue ;
		
		//cerr<<curr<<" "<<akt<<" "<<(1LL<<i)<<"\n";
		int R=m-1, j;
		bool ok=true;
		vector<pair<int,int>> lol;
		for(j=n-1;R>=0 && j>=0;j--) {
			while(R>=0 && abs(a[j]-b[R])>akt) {
				R--;
			}
			ok&=(R>=0&&(abs(a[j]-b[R])<=akt));
			if(akt==198502912) cerr<<j<<" "<<R<<" "<<ok<<"\n";
			lol.push_back({j, R});
			R--;
		}
		ok&=j==-1;
		//if(lol.size()==n) {
		if(ok) {
			curr=akt;
			
		}
	}
	
	cout<<curr<<"\n";
	
	
	return 0;
}

Compilation message

cipele.cpp:61:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 3448 KB Output is correct
2 Correct 49 ms 3704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 3704 KB Output is correct
2 Correct 56 ms 3832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 8 ms 800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 8 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 8 ms 800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 8 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 740 KB Output is correct
2 Correct 8 ms 764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 6300 KB Output is correct
2 Correct 59 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 6864 KB Output is correct
2 Correct 60 ms 4660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 6192 KB Output is correct
2 Correct 93 ms 6640 KB Output is correct