Submission #892339

# Submission time Handle Problem Language Result Execution time Memory
892339 2023-12-25T08:11:41 Z LittleFlowers__ Cipele (COCI18_cipele) C++17
90 / 90
32 ms 2908 KB
#include <bits/stdc++.h>

using namespace std;

int32_t main() {
  if (fopen("input.txt", "r")) {
    freopen("input.txt", "r", stdin);
  }

  cin.tie(0)->sync_with_stdio(0);

  int n, m; cin >> n >> m;
  vector<int> a(n), b(m);

  for (int &i : a) cin >> i;
  for (int &i : b) cin >> i;

  if (n > m) swap(n, m), swap(a, b);
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());


  int le = 0, mi, ri = 1e9, answer;
  while (le <= ri) {
    mi = (le + ri) / 2;

    bool okay = true;
    
    int j = 0;
    for (int i = 0; i < a.size(); ++i) {
      while (j < b.size() && abs(a[i] - b[j]) > mi) j += 1;

      if (j == b.size()) { okay = false; break; }
      j += 1;
    }

    if (okay) answer = mi, ri = mi - 1;
    else le = mi + 1;
  }

  cout << answer << '\n';
}

Compilation message

cipele.cpp: In function 'int32_t main()':
cipele.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for (int i = 0; i < a.size(); ++i) {
      |                     ~~^~~~~~~~~~
cipele.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |       while (j < b.size() && abs(a[i] - b[j]) > mi) j += 1;
      |              ~~^~~~~~~~~~
cipele.cpp:33:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |       if (j == b.size()) { okay = false; break; }
      |           ~~^~~~~~~~~~~
cipele.cpp:7:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
cipele.cpp:41:21: warning: 'answer' may be used uninitialized in this function [-Wmaybe-uninitialized]
   41 |   cout << answer << '\n';
      |                     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2652 KB Output is correct
2 Correct 32 ms 2896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 2904 KB Output is correct
2 Correct 32 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 2400 KB Output is correct
2 Correct 19 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2652 KB Output is correct
2 Correct 14 ms 2136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2396 KB Output is correct
2 Correct 28 ms 2660 KB Output is correct