답안 #699722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
699722 2023-02-17T20:48:39 Z inwbear Cipele (COCI18_cipele) C++14
90 / 90
49 ms 3068 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int n,m,x,ans,st,ed,md;
vector<int>l,r;
bool chk(int k){
  int cur=0,co=0;
  for(int i=0;i<l.size();i++){
    while(abs(l[i]-r[cur])>k){
      cur++;
      if(cur>=r.size())break;
    }
    if(cur>=r.size())break;
    co++;
    cur++;
    if(cur>=r.size())break;
  }
  if(co==l.size())return true;
  else return false;
}
int main(){
  scanf("%d %d",&n,&m);
  for(int i=0;i<n;i++){
    scanf("%d",&x);
    l.pb(x);
  }
  for(int i=0;i<m;i++){
    scanf("%d",&x);
    r.pb(x);
  }
  sort(l.begin(),l.end());
  sort(r.begin(),r.end());
  if(m<n)swap(n,m),swap(l,r);
  ans=INT_MAX,st=0,ed=(int)1e9;
  while(st<=ed){
    md=(st+ed)/2;
    if(chk(md)){
      ans=min(ans,md);
      ed=md-1;
    }
    else{
      st=md+1;
    }
  }
  printf("%d",ans);
}

Compilation message

cipele.cpp: In function 'bool chk(int)':
cipele.cpp:8:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |   for(int i=0;i<l.size();i++){
      |               ~^~~~~~~~~
cipele.cpp:11:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |       if(cur>=r.size())break;
      |          ~~~^~~~~~~~~~
cipele.cpp:13:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     if(cur>=r.size())break;
      |        ~~~^~~~~~~~~~
cipele.cpp:16:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     if(cur>=r.size())break;
      |        ~~~^~~~~~~~~~
cipele.cpp:18:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |   if(co==l.size())return true;
      |      ~~^~~~~~~~~~
cipele.cpp: In function 'int main()':
cipele.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |   scanf("%d %d",&n,&m);
      |   ~~~~~^~~~~~~~~~~~~~~
cipele.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%d",&x);
      |     ~~~~~^~~~~~~~~
cipele.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%d",&x);
      |     ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 2628 KB Output is correct
2 Correct 39 ms 2988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 2608 KB Output is correct
2 Correct 44 ms 3068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 3 ms 440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 2504 KB Output is correct
2 Correct 27 ms 1848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 2496 KB Output is correct
2 Correct 19 ms 2132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 2500 KB Output is correct
2 Correct 35 ms 2844 KB Output is correct