Submission #969283

#TimeUsernameProblemLanguageResultExecution timeMemory
969283mariaclaraWiring (IOI17_wiring)C++17
0 / 100
1061 ms12620 KiB
#include "wiring.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pii; const int INF = 1e9+10; const ll LINF = 1e18+10; #define all(x) x.begin(), x.end() #define sz(x) x.size() #define mk make_pair #define pb push_back #define f first #define s second ll min_total_length(vector<int> r, vector<int> b) { vector<pii> p; r.pb(INF); b.pb(INF); p.pb({-1,-1}); for(int i = 0, j = 0; r[i] != b[j]; ) { if(r[i] < b[j]) p.pb({r[i],0}), i++; else p.pb({b[j],1}), j++; } int n = sz(p); vector<ll> dp(n, LINF), v(n, 0), m(n, 0), prefix(n, 0); dp[0] = 0; for(int i = 1, last = -1, at = 1; i < n; i++) { prefix[i] = prefix[i-1] + p[i].f; if(p[i].s != p[i-1].s) last = at, at = i; if(at == 1) continue; for(int j = at-1; j >= last; j--) { ll x = prefix[i] - prefix[at-1]; ll y = prefix[at-1] - prefix[j-1]; ll R = x - y; if(i-at+1 >= at-j) R -= (i-at+1-at+j)*p[at-1].f; else R += (at-j-i+at-1)*p[at].f; dp[i] = min(dp[i], R+dp[j-1]); } //cout << dp[i] << "\n" << at << " " << p[i].f << " " << p[i].s << " "; } return dp[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...