Submission #423055

#TimeUsernameProblemLanguageResultExecution timeMemory
423055Rudy420Wiring (IOI17_wiring)C++17
100 / 100
74 ms7060 KiB
#include <bits/stdc++.h> using namespace std; #define x first #define y second #define lg length() #define pb push_back #define INF 2000000005 #define LINF 1000000000000000005 #define all(x) (x).begin(), (x).end() #define rep(i, a, b) for(int i = a; i < (b); ++i) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int rand(int l,int r){return uniform_int_distribution<int>(l,r)(rng);} #include "wiring.h" long long min_total_length(vector<int> r, vector<int> b) { int n = sz(r) + sz(b); vector <pii> a; for(int i : r) a.pb({i, 0}); for(int i : b) a.pb({i, 1}); sort(all(a)); vector <ll> dp(n+1); int j = 0; ll sum = 0; dp[0] = 0; for(int i=0;i<n;i++){ dp[i+1] = LINF; if(a[i].y == 0){ auto it = lower_bound(all(b), a[i].x); if(it != b.end()) dp[i+1] = min(dp[i+1], dp[i] + (*it) - a[i].x); if(it != b.begin()) it--, dp[i+1] = min(dp[i+1], dp[i] + a[i].x - (*it)); } else{ auto it = lower_bound(all(r), a[i].x); if(it != r.end()) dp[i+1] = min(dp[i+1], dp[i] + (*it) - a[i].x); if(it != r.begin()) it--, dp[i+1] = min(dp[i+1], dp[i] + a[i].x - (*it)); } if(i && a[i].y != a[i-1].y) j = i, sum = 0; if(j && a[i].y != a[j-1].y) j--, sum += a[i].x - a[j].x, dp[i+1] = min(dp[i+1], dp[j] + sum); } 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...