Submission #416249

#TimeUsernameProblemLanguageResultExecution timeMemory
416249prvocisloWiring (IOI17_wiring)C++17
100 / 100
78 ms11144 KiB
#include "wiring.h" #include <bits/stdc++.h> typedef long long ll; using namespace std; const ll inf = 1e18; long long min_total_length(std::vector<int> r, std::vector<int> b) { int n = r.size(), m = b.size(); vector<pair<ll, int> > rb; for (int i = 0; i < n; i++) rb.push_back({r[i], 0}); for (int i = 0; i < m; i++) rb.push_back({b[i], 1}); sort(rb.begin(), rb.end()); vector<vector<ll> > vv; for (int i = 0; i < rb.size(); i++) { if (!i || rb[i-1].second != rb[i].second) vv.push_back({}); vv.back().push_back(rb[i].first); } vector<ll> dp(1, 0); for (int it = 0; it < vv.size(); it++) { const vector<ll> &v = vv[it]; ll nx = (it == vv.size() - 1 ? 1e10 : vv[it + 1][0]), pv = (it ? vv[it - 1].back() : -1e10); int siz = v.size(); dp.resize(siz + 1, inf); for (int i = 1; i <= siz; i++) dp[i] = min(dp[i], dp[i - 1] + v[0] - pv); // pridame jednu extra hranu vector<ll> nwdp(siz + 1, inf); ll sf = 0, pf = 0; for (ll i : v) sf += v.back() - i; for (int i = 0; i <= siz; i++) // kolko sparujeme s predoslym usekom { if (i) pf += v[i - 1] - v[0], sf -= v.back() - v[i - 1]; nwdp[siz - i] = dp[i] + pf + sf + (nx - v.back()) * (siz - i); // vyskusame dlzku prefixu a sufixu } for (int i = siz; i > 0; i--) nwdp[i - 1] = min(nwdp[i - 1], nwdp[i]); // zahodime jednu hranu dp = nwdp; } return dp[0]; }

Compilation message (stderr)

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:14:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for (int i = 0; i < rb.size(); i++)
      |                  ~~^~~~~~~~~~~
wiring.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for (int it = 0; it < vv.size(); it++)
      |                   ~~~^~~~~~~~~~~
wiring.cpp:23:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   ll nx = (it == vv.size() - 1 ? 1e10 : vv[it + 1][0]), pv = (it ? vv[it - 1].back() : -1e10);
      |            ~~~^~~~~~~~~~~~~~~~
#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...