제출 #56573

#제출 시각아이디문제언어결과실행 시간메모리
56573naderjemel전선 연결 (IOI17_wiring)C++14
0 / 100
4 ms584 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000000; const long long inf = 1LL<<60; int nex[MAXN]; long long sum[MAXN], dp[MAXN], f[MAXN]; inline long long get_sum(const int lo, const int hi){ return sum[lo] - sum[hi+1]; } long long min_total_length(vector <int> red, vector <int> blue){ int n = blue.size(), m = red.size(); vector< pair<int,int> > q; int pb = 0, pr = 0; while (pb < n || pr < m){ if ((pr == m) || (pb < n && blue[pb] < red[pr])) q.push_back(make_pair(blue[pb++], 0)); else q.push_back(make_pair(red[pr++], 1)); } int nm = n + m; sum[nm] = 0, f[nm] = 0; dp[nm-1] = inf, nex[nm-1] = nm, sum[nm-1] = q[nm-1].first; for (int i = nm - 2; i >= 0; i--){ dp[i] = inf; sum[i] = sum[i+1] + q[i].first; nex[i] = q[i].second == q[i+1].second ? nex[i+1] : i+1; if (nex[i] == i+1){ for (int j = nex[i+1]-1; j >= i+1; j--) f[j] = min(dp[j], q[j].first - q[i].first + dp[j+1]); } if (nex[i] == nm) continue; dp[i] = min(inf, dp[i+1] + q[nex[i]].first - q[i].first); int sz = nex[i] - i; dp[i] = min(dp[i], get_sum(nex[i], nex[i]+sz-1) - get_sum(i, nex[i]-1) + f[nex[i]+sz]); } return dp[0]; }
#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...