# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
88316 | 2018-12-05T09:22:02 Z | ltomic | Cipele (COCI18_cipele) | C++14 | 63 ms | 17220 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 2680 KB | Output is correct |
2 | Correct | 60 ms | 4628 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 60 ms | 6488 KB | Output is correct |
2 | Correct | 63 ms | 8232 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 8232 KB | Output is correct |
2 | Correct | 5 ms | 8232 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 8232 KB | Output is correct |
2 | Correct | 5 ms | 8232 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 8232 KB | Output is correct |
2 | Correct | 5 ms | 8232 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 8232 KB | Output is correct |
2 | Correct | 5 ms | 8232 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 8384 KB | Output is correct |
2 | Correct | 5 ms | 8448 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 56 ms | 10468 KB | Output is correct |
2 | Correct | 36 ms | 11428 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 55 ms | 13196 KB | Output is correct |
2 | Correct | 31 ms | 14188 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 54 ms | 15576 KB | Output is correct |
2 | Correct | 51 ms | 17220 KB | Output is correct |