답안 #95200

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
95200 2019-01-28T13:56:44 Z Ort Cipele (COCI18_cipele) C++11
90 / 90
46 ms 2936 KB
#include<algorithm>
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	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(a.begin(),a.end()); sort(b.begin(),b.end());
	if(n>m) swap(a,b);
	int low = -1, high = 1e9, mid, t;
	bool valid;
	while(high-low>1) {
		mid = (low+high)>>1;
		t = 0; valid = 1;
		for(int i=0;i<a.size();i++) {
			if(t>=b.size()) {
				valid = 0;
				break;
			}
			while(t<b.size() && b[t]<=a[i] && a[i]-b[t]>mid) t++;
			if(t>=b.size() || abs(a[i]-b[t])>mid) {
				valid = 0;
				break;
			}
			t++;
		}
		if(valid) high = mid;
		else low = mid;
	}
	cout << high;
	return 0;
}

Compilation message

cipele.cpp: In function 'int main()':
cipele.cpp:23:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<a.size();i++) {
               ~^~~~~~~~~
cipele.cpp:24:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(t>=b.size()) {
       ~^~~~~~~~~~
cipele.cpp:28:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while(t<b.size() && b[t]<=a[i] && a[i]-b[t]>mid) t++;
          ~^~~~~~~~~
cipele.cpp:29:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(t>=b.size() || abs(a[i]-b[t])>mid) {
       ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 2808 KB Output is correct
2 Correct 46 ms 2936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 2936 KB Output is correct
2 Correct 42 ms 2936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 2424 KB Output is correct
2 Correct 26 ms 1784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 2680 KB Output is correct
2 Correct 27 ms 2056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 2396 KB Output is correct
2 Correct 37 ms 2576 KB Output is correct