Submission #637040

# Submission time Handle Problem Language Result Execution time Memory
637040 2022-08-31T10:15:19 Z Metal_Sonic Cipele (COCI18_cipele) C++17
0 / 90
41 ms 2892 KB
#include <bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template<class T> using indexed_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define ll long long
#define sz(x) (int)(x).size()
#define all(x) x.begin() , x.end()
void Sonic(string name = "") {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}
int xd[] = {0, 0, 1, -1, 1, 1, -1, -1};
int yd[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int mxn = 1005;
int n,m;
bool valid(int ugl, vector<int>&ls, vector<int>&rs){
    int ptl = 0, ptr = 0;
    int paired = 0;
    while(ptl<n&&ptr<m){
        if(abs(ls[ptl]-rs[ptr])<=ugl){
            paired++,ptl++,ptr++;
        }else {
            ptr++;
        }
    }
    if(paired!=n)return false;
    else return true;
}
void run_test_case(){
    cin>>n>>m;
    vector<int>l(n),r(m);
    for(int i = 0; i < n; i++)cin>>l[i];
    for(int i = 0; i < m; i++)cin>>r[i];
    sort(all(l));
    sort(all(r));
    if(n>m){
        swap(n,m);
        swap(l,r);
    }
    int ans = 1e5;
    int left = 0, right = 1e5;
    while(left<=right){
        int mid = (left+right)/2;
        if(valid(mid,l,r)){
            ans = mid;
            right = mid-1;
        }else left = mid+1;
    }
    cout<<ans;
}
int main(){
    Sonic();
    int T = 1;
    //cin>>T;
    while(T--){
        run_test_case();
    }
    return 0;
}

Compilation message

cipele.cpp: In function 'void Sonic(std::string)':
cipele.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen((name+".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cipele.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen((name+".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 27 ms 2644 KB Output is correct
2 Incorrect 41 ms 2892 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 2888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 368 KB Output is correct
2 Incorrect 2 ms 460 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Incorrect 2 ms 456 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 396 KB Output is correct
2 Incorrect 3 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 412 KB Output is correct
2 Incorrect 3 ms 460 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 2404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 2556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 2352 KB Output isn't correct
2 Halted 0 ms 0 KB -