Submission #248721

#TimeUsernameProblemLanguageResultExecution timeMemory
248721MarcoMeijerWiring (IOI17_wiring)C++14
0 / 100
1 ms384 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 = 1e6; vi f[2]; ll N[2], n = 0; ll a[MX], b[MX], sm[MX], ch[MX], CENT[MX]; ll getCost(ll bg, ll ed) { if(ch[ed] - ch[bg] != 1) return INF; ll cent = CENT[ed-1]; ll cost = 0; REP(i,bg,cent) cost -= a[i]; REP(i,cent,ed+1) cost += a[i]; ll left = cent - bg; ll right = ed+1 - cent; if(left < right) { cost += a[cent]*(right - left); } else { cost += a[cent-1]*(right - left); } return cost; } 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 priority_queue<ii, vii, greater<ii>> pq; RE(i,2) RE(j,N[i]) pq.push({f[i][j], i}); while(!pq.empty()) { ii p = pq.top(); pq.pop(); a[n] = p.fi; b[n] = p.se; n++; } sm[0] = 0; ch[0] = 0; CENT[0] = 0; REP(i,1,n+1) { ch[i] = ch[i-1]; sm[i] = sm[i-1]+a[i-1]; CENT[i] = CENT[i-1]; if(b[i] != b[i-1]) ch[i]++, CENT[i]=i; } return getCost(0, n-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...