Submission #903858

#TimeUsernameProblemLanguageResultExecution timeMemory
903858math_rabbit_1028Wiring (IOI17_wiring)C++14
0 / 100
0 ms352 KiB
#include <bits/stdc++.h> #include "wiring.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; vector<pii> arr; vector<ll> sum; vector<ll> dp; ll min_total_length(vector<int> R, vector<int> B) { arr.push_back({0, 0}); for (int i = 0; i < R.size(); i++) arr.push_back({R[i], 0}); for (int i = 0; i < B.size(); i++) arr.push_back({B[i], 1}); sort(arr.begin() + 1, arr.end()); dp = vector<ll>(arr.size(), 1e18); sum = vector<ll>(arr.size(), 0); for (int i = 1; i < sum.size(); i++) sum[i] = sum[i - 1] + arr[i].first; int a, b, last, i = 1; dp[1] = 0; while (arr[i].second == arr[i+1].second) { i++; dp[i] = 0; } b = i; for (i++; i < arr.size(); i++) { if (arr[i].second != arr[i-1].second) { a = b; b = 0; last = arr[i-1].first; } b++; if (b <= a) { dp[i] = min(dp[i], dp[i-1] + arr[i].first - last); dp[i] = min(dp[i], dp[i-2*b] + (sum[i] - sum[i-b]) - (sum[i-b] - sum[i-2*b])); } else { dp[i] = min(dp[i], dp[i-1] + arr[i].first - last); } //cout << i << " " << dp[i] << "\n"; } return dp[arr.size()-1]; }

Compilation message (stderr)

wiring.cpp: In function 'll min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:12:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |  for (int i = 0; i < R.size(); i++) arr.push_back({R[i], 0});
      |                  ~~^~~~~~~~~~
wiring.cpp:13:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  for (int i = 0; i < B.size(); i++) arr.push_back({B[i], 1});
      |                  ~~^~~~~~~~~~
wiring.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for (int i = 1; i < sum.size(); i++) sum[i] = sum[i - 1] + arr[i].first;
      |                  ~~^~~~~~~~~~~~
wiring.cpp:26:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for (i++; i < arr.size(); i++) {
      |            ~~^~~~~~~~~~~~
wiring.cpp:38:48: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |    dp[i] = min(dp[i], dp[i-1] + arr[i].first - last);
      |                                                ^~~~
wiring.cpp:33:3: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
   33 |   if (b <= a) {
      |   ^~
#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...