Submission #99092

#TimeUsernameProblemLanguageResultExecution timeMemory
99092figter001Wiring (IOI17_wiring)C++14
0 / 100
3 ms256 KiB
#include "wiring.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; const int nax = 2e5 + 50; ll dp[nax]; long long min_total_length(vector<int> r, vector<int> b) { vector<pair<ll,int>> a; for(int i : r) a.push_back({i,0}); for(int i : b) a.push_back({i,1}); sort(a.begin(),a.end()); int n = a.size(); for(int i=0;i<=n;i++) dp[i] = 1e18; dp[0] = 0; int lr = -1,lb = -1; int id1 = -1,id2 = -1; for(int i=1;i<=n;i++){ pair<int,int> cur = a[i-1]; ll at = cur.first; if(cur.first == 0){ if(lb != -1) dp[i] = min(dp[i],dp[id2-1] + at - lb); lr = at; id1 = i; }else{ if(lr != -1) dp[i] = min(dp[i],dp[id1-1] + at - lr); lb = at; id2 = i; } } return dp[n]; }
#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...