# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
88316 | ltomic | Cipele (COCI18_cipele) | C++14 | 63 ms | 17220 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
using par = pair<int, int>;
using llint = long long;
const int MAXN = 1e5+5;
const llint MAXNUM = 1e18;
const int MAXV = 1e9;
int n, m;
int *a, *b;
map<par, llint> mem;
int l[MAXN], r[MAXN], low[MAXN], high[MAXN], best[MAXN], cnt[MAXN];
llint dp(int i, int j) {
if (i == n) return 0;
par p = par(i, j);
if (mem.find(par(i, j)) != mem.end()) return mem[par(i, j)];
if (j > high[i]) return mem[p] = MAXNUM;
if (j < low[i]) return mem[p] = dp(i, low[i]);
return mem[p] = min(dp(i, j+1), dp(i+1, j+1)+abs(a[i]-b[j]));
}
bool f(int x) {
int pt = 0;
for (int i = 0; i < n; ++i) {
while (pt < m && a[i]-b[pt] > x) pt++;
if (pt >= m || abs(a[i]-b[pt]) > x) return false;
pt++;
}
return true;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) {
scanf("%d", l+i);
}
for (int i = 0; i < m; ++i) {
scanf("%d", r+i);
}
if (n < m) {
a = l;
b = r;
} else {
a = r;
b = l;
swap(n, m);
}
/*
for (int i = 0; i < n; ++i) {
printf("%d ", a[i]);
}
printf("\n");
for (int i = 0; i < m; ++i) {
printf("%d ", b[i]);
}
printf("\n");
*/
sort(a, a+n);
sort(b, b+m);
int lo = 0, hi = MAXV;
while (lo < hi) {
int mid = (lo+hi)/2;
if (f(mid)) {
hi = mid;
} else {
lo = mid+1;
}
}
printf("%d\n", lo);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |