Submission #1307338

#TimeUsernameProblemLanguageResultExecution timeMemory
1307338gogoim045Cipele (COCI18_cipele)C++20
90 / 90
30 ms1856 KiB
#include <bits/stdc++.h>  
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 

void setIO(string name = "") {
ios_base::sync_with_stdio(0);
cin.tie(0);
if (!name.empty()) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
 }
}

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define printarr(x) for (ll _do_not_use : x) {cout << _do_not_use << " ";}
#define arrayinp(x) for (size_t i = 0; i < x.size(); i++){cin >> x[i];}

#ifndef ONLINE_JUDGE
#define dbg(x) cout<<#x<<" = "<<x<<ln
#else
#define dbg(x)
#endif


void solve(){
    ll n, m;
    cin >> n >> m;
    v64 L(n+1), R(m+1);
    for (ll i = 1; i <= n; i++) cin >> L[i];
    for (ll i = 1; i <= m; i++) cin >> R[i];
    sort(all(L));
    sort(all(R));
    if (m<n) {swap(L, R); swap(m, n);}
    // n<=m;
    // can I check whether we can get ugliness less than equal to k,
    auto check = [&](ll k) {
        ll j = 1;
        for (ll i = 1; i <= n; i++)
        {
            while (j<=m&&abs(R[j]-L[i])>k) j++;
            if (j==m+1) return 0;
            j++;
        }
        return 1;
    };
    // we can always get ugliness of <=right and can never get<=left
    ll left=-1, right=abs(L[1]-R[m]);
    while (left+1<right)
    {
        ll mid = left+(right-left)/2;
        if (check(mid)) right = mid;
        else left = mid;
    }
    cout << right << ln;
}

int main()
{
    fast_cin();
    ll t = 1;
    // cin >> t;
    for(ll it=1;it<=t;it++) {
        solve();
    }
    return 0;
}

Compilation message (stderr)

cipele.cpp: In function 'void setIO(std::string)':
cipele.cpp:27:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 | freopen((name + ".in").c_str(), "r", stdin);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cipele.cpp:28:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 | freopen((name + ".out").c_str(), "w", stdout);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...