답안 #672851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
672851 2022-12-18T12:59:47 Z tvladm2009 Cipele (COCI18_cipele) C++14
90 / 90
55 ms 3168 KB
#include <bits/stdc++.h>

using ll = long long;

bool check(int x, std::vector<int> left, std::vector<int> right) {
  int ptr1 = 0, ptr2 = 0;
  int cnt = 0;
  while(ptr1 < left.size() && ptr2 < right.size()) {
    if(abs(left[ptr1] - right[ptr2]) <= x) {
      cnt++;
      ptr1++;
      ptr2++;
    } else
      ptr2++;
  }
  return (cnt == left.size());
}

int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);

  int n, m;
  std::cin >> n >> m;
  std::vector<int> x(n), y(m);
  for(int i = 0;i < n; i++)
    std::cin >> x[i];
  for(int i = 0;i < m; i++)
    std::cin >> y[i];
  std::sort(x.begin(), x.end());
  std::sort(y.begin(), y.end());
  if(n > m) {
    std::swap(n, m);
    std::swap(x, y);
  }
  int from = 0, to = 1e9, result = 0;
  while(from <= to) {
    int mid = (from + to) / 2;
    if(check(mid, x, y)) {
      result = mid;
      to = mid - 1;
    } else
      from = mid + 1;
  }
  std::cout << result;
  return 0;
}

Compilation message

cipele.cpp: In function 'bool check(int, std::vector<int>, std::vector<int>)':
cipele.cpp:8:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |   while(ptr1 < left.size() && ptr2 < right.size()) {
      |         ~~~~~^~~~~~~~~~~~~
cipele.cpp:8:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |   while(ptr1 < left.size() && ptr2 < right.size()) {
      |                               ~~~~~^~~~~~~~~~~~~~
cipele.cpp:16:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |   return (cnt == left.size());
      |           ~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 1872 KB Output is correct
2 Correct 53 ms 2128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 1880 KB Output is correct
2 Correct 51 ms 2020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 1620 KB Output is correct
2 Correct 31 ms 2264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 1700 KB Output is correct
2 Correct 31 ms 2596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 1564 KB Output is correct
2 Correct 50 ms 3168 KB Output is correct