Submission #43199

#TimeUsernameProblemLanguageResultExecution timeMemory
43199szawinisWiring (IOI17_wiring)C++14
7 / 100
65 ms8928 KiB
#include "wiring.h" #include <bits/stdc++.h> #define pos first #define col second using namespace std; using ll = long long; const int N = 1e5+1; const ll INF = 1e17; int n; vector<pair<int,int> > a; ll s[N], dp[N]; ll min_total_length(std::vector<int> r, std::vector<int> b) { n = r.size() + b.size(); for(int i = 0; i < r.size(); i++) a.emplace_back(r[i], 0); for(int i = 0; i < b.size(); i++) a.emplace_back(b[i], 1); a.emplace_back(INT_MIN, INT_MIN); sort(a.begin(), a.end()); for(int i = 1; i <= n; i++) s[i] = s[i-1] + a[i].pos; fill(dp+1, dp+n+1, INF); for(int i = 2; i <= n; i++) { // case segments completely disjoint int k = i-1; while(k >= 0 && a[k].col == a[i].col) --k; if(!k) continue; for(int j = k-1; j >= 0 && a[j+1].col == a[k].col; j--) { ll res = dp[j] + (s[i] - s[k]) - (s[k] - s[j]); if(i-k > k-j) res -= 1ll * ((i-k) - (k-j)) * a[k].pos; else if(i-k < k-j) res += 1ll * ((k-j) - (i-k)) * a[k+1].pos; dp[i] = min(res, dp[i]); } // case segments intersect at one node if(k-1 >= 1 && a[k-1].col == a[i].col) dp[i] = min(dp[k] + s[i] - s[k] - 1ll * (i-k) * a[k].pos, dp[i]); } return dp[n]; }

Compilation message (stderr)

wiring.cpp: In function 'll min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:15:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < r.size(); i++) a.emplace_back(r[i], 0);
                   ^
wiring.cpp:16:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < b.size(); i++) a.emplace_back(b[i], 1);
                   ^
#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...