Submission #168840

#TimeUsernameProblemLanguageResultExecution timeMemory
168840Mamnoon_SiamCipele (COCI18_cipele)C++17
18 / 90
613 ms10712 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; const int maxn = 1e5 + 5; int n, m; int a[maxn], b[maxn]; vector<int> g[maxn]; int par[maxn]; int find(int u) { return par[u] == u ? u : par[u] = find(par[u]); } bool can(int del) { for(int i = 1; i <= m; i++) { g[i].clear(); } for(int i = 1; i <= n; i++) { int l = lower_bound(b + 1, b + 1 + m, a[i] - del) - b; int r = upper_bound(b + 1, b + 1 + m, a[i] + del) - b - 1; // cout << l << ' ' << r << endl; g[r].emplace_back(l); } iota(par, par + 1 + m + 1, 0); for(int r = 1; r <= m; r++) { sort(g[r].begin(), g[r].end(), [](int x, int y){ return x > y; }); for(int l : g[r]) { int mn = find(l); if(mn > r) { return 0; } else { par[mn] = mn + 1; } } } return 1; } int main(int argc, char const *argv[]) { #ifdef LOCAL freopen("in", "r", stdin); #endif cin >> n >> m; if(n <= m) { for(int i = 1; i <= n; i++) { cin >> a[i]; } for(int i = 1; i <= m; i++) { cin >> b[i]; } } else { for(int i = 1; i <= n; i++) { cin >> b[i]; } for(int i = 1; i <= m; i++) { cin >> a[i]; } swap(n, m); } sort(a + 1, a + 1 + n); sort(b + 1, b + 1 + n); int lo = 0, hi = 1e9, opt = -1, mid; while(lo <= hi) { mid = lo + hi >> 1; if(can(mid)) { opt = mid; hi = mid - 1; } else { lo = mid + 1; } } cout << opt << endl; return 0; }

Compilation message (stderr)

cipele.cpp: In function 'int main(int, const char**)':
cipele.cpp:69:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   mid = lo + hi >> 1;
         ~~~^~~~
#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...