Submission #283272

#TimeUsernameProblemLanguageResultExecution timeMemory
283272DystoriaXWiring (IOI17_wiring)C++14
0 / 100
52 ms9960 KiB
#include "wiring.h" #include <algorithm> #include <iostream> using namespace std; vector<pair<int, int> > v; const long long INF = 1e18; long long dp[100010]; long long min_total_length(std::vector<int> r, std::vector<int> b) { for(auto &k : r) v.emplace_back(k, 0); for(auto &k : b) v.emplace_back(k, 1); sort(v.begin(), v.end()); int vs = 1 - (v.begin() -> second); int last = -1; for(int i = 1; i < (int) v.size(); i++){ if(v[i].second == v[i - 1].second) continue; else {last = i; break;} } for(int i = 0; i < (int) v.size(); i++) dp[i] = 1e17; // cerr << last << "\n"; int lpos = v[last - 1].first, cpos = v[last].first; int connected = 0; for(int i = last; i < (int) v.size(); i++){ if(v[i].second == v[i - 1].second){ // cerr << i << " " << connected << "\n"; if(connected == 1) dp[i] = dp[i - 1] + v[i].first - lpos; else connected--, dp[i] = dp[i - 1] + v[i].first - cpos; } else { lpos = v[i - 1].first; cpos = v[i].first; long long cost = 0; for(int j = i - 1; j >= 0; j--){ if(v[j].second == v[i].second) break; cost += v[i].first - v[j].first; long long pen = (j == 0) ? 0 : dp[j - 1]; if(dp[i] >= pen + cost){ dp[i] = pen + cost; connected = i - j; } } } // cerr << v[i].first << " " << i << " = " << dp[i] << "\n"; } return dp[v.size() - 1]; }

Compilation message (stderr)

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:17:6: warning: unused variable 'vs' [-Wunused-variable]
   17 |  int vs = 1 - (v.begin() -> second);
      |      ^~
#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...