Submission #247664

#TimeUsernameProblemLanguageResultExecution timeMemory
247664MarcoMeijerWiring (IOI17_wiring)C++14
0 / 100
1094 ms13800 KiB
#include "wiring.h" #include <bits/stdc++.h> using namespace std; //macros typedef long long ll; typedef pair<int, int> ii; typedef pair<ll, ll> lll; typedef tuple<int, int, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<ll> vll; typedef vector<lll> vlll; #define REP(a,b,c) for(int a=int(b); a<int(c); a++) #define RE(a,c) REP(a,0,c) #define RE1(a,c) REP(a,1,c+1) #define REI(a,b,c) REP(a,b,c+1) #define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--) #define INF 1e18 #define pb push_back #define fi first #define se second #define sz size() const int MX = 6e5; priority_queue<ii, vii, greater<ii>> pq; int n[2], p[2], m=0; vi f[2]; ll a[MX], b[MX], sm[MX]; ll dp[MX], ch[MX]; ll md[MX]; ll ans=0; ll min_total_length(std::vector<int> R, std::vector<int> B) { f[0] = R; f[1] = B; RE(i,2) n[i] = f[i].sz; // fill a and b RE(i,2) RE(j,n[i]) pq.push({f[i][j], i}); while(!pq.empty()) { a[m] = pq.top().fi; b[m] = pq.top().se; pq.pop(); m++; } ch[0]=0; md[0]=0; sm[0]=0; REP(i,1,m) { md[i] = md[i-1]; ch[i] = ch[i-1]; sm[i] = sm[i-1] + a[i-1]; if(b[i] != b[i-1]) ch[i]++, md[i]=i; } sm[m] = sm[m-1]+a[m-1]; dp[0] = 0; REP(i,1,m+1) { ll mn=INF; dp[i] = INF; REV(j,md[max(0ll,md[i-1]-1)],md[i-1]) { mn = min(mn, dp[j]); ll bg = j, ed = i-1; ll mid = md[ed]; ll cost = 0; cost += a[mid-1]*(mid-bg) - (sm[mid]-sm[bg]); cost += (sm[ed+1]-sm[mid]) - a[mid]*(ed+1-mid); cost += (a[mid]-a[mid-1])*max(mid-bg,ed-mid+1); dp[i] = min(dp[i], mn + cost); } } return dp[m]; }
#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...