답안 #95553

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
95553 2019-02-02T03:57:46 Z kimcoding Cipele (COCI18_cipele) C++17
90 / 90
50 ms 2808 KB
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

#define all(x) (x).begin(), (x).end()

typedef vector <int> vi;

int n, m, ans;
vi a, b;

bool function(int x) {
	for (int i = 1, j = 1; i <= n; i++) {
		while (j <= m && a[i] - b[j] > x) j++;
		if (j > m || b[j] - a[i] > x) return false;
		j++;
	}
	return true;
}

int main() {
	scanf("%d %d", &n, &m);
	a = vi(n + 1), b = vi(m + 1);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
	sort(all(a));
	sort(all(b));

	if (n > m) swap(n, m), swap(a, b);
	int left = 0, right = 1e9;
	while (left <= right) {
		int mid = (left + right) / 2;
		if (function(mid)) {
			ans = mid;
			right = mid - 1;
		}
		else left = mid + 1;
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message

cipele.cpp: In function 'int main()':
cipele.cpp:23: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:25:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
                               ~~~~~^~~~~~~~~~~~~
cipele.cpp:26:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
                               ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 1144 KB Output is correct
2 Correct 50 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 1244 KB Output is correct
2 Correct 50 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 380 KB Output is correct
2 Correct 4 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 1016 KB Output is correct
2 Correct 30 ms 1824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 1060 KB Output is correct
2 Correct 23 ms 2024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 1016 KB Output is correct
2 Correct 42 ms 2424 KB Output is correct