Submission #88316

#TimeUsernameProblemLanguageResultExecution timeMemory
88316ltomicCipele (COCI18_cipele)C++14
90 / 90
63 ms17220 KiB
#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)

cipele.cpp: In function 'int main()':
cipele.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~
cipele.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", l+i);
     ~~~~~^~~~~~~~~~~
cipele.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", r+i);
     ~~~~~^~~~~~~~~~~
#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...