#include "wiring.h"
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define INF 1145141919
#define _1 first
#define _2 second
using namespace std;
typedef pair<int, int> P;
inline void chmin(long long &x, long long v) { if(x>v)x=v; }
int N;
long long dp[401][401][401];
long long cost[401];
long long min_total_length(vector<int> R, vector<int> B) {
vector<P> all;
for (int x : R) all.pb(P(x, 0));
for (int x : B) all.pb(P(x, 1));
sort(all(all));
N = all.size();
rep(i, N) {
cost[i] = INF;
if (all[i]._2 == 0) {
auto it = lower_bound(all(B), all[i]._1);
if (it != B.end()) chmin(cost[i], *it-all[i]._1);
if (it != B.begin()) chmin(cost[i], all[i]._1-*(--it));
}
else {
auto it = lower_bound(all(R), all[i]._1);
if (it != R.end()) chmin(cost[i], *it-all[i]._1);
if (it != R.begin()) chmin(cost[i], all[i]._1-*(--it));
}
}
//rep(i,N)cout<<cost[i]<<",";cout<<"\n";
rep(i, N+1) rep(j, N+1) rep(k, N+1) dp[i][j][k] = INF;
dp[0][0][0] = 0;
rep(i, N) {
int pos = all[i]._1, color = all[i]._2;
rep(j, N) {
rep(k, N) {
// [
if (all[i]._2 == 0) chmin(dp[i+1][j+1][k], dp[i][j][k]-pos);
if (all[i]._2 == 1) chmin(dp[i+1][j][k+1], dp[i][j][k]-pos);
// ]
if (all[i]._2 == 1 && j > 0) chmin(dp[i+1][j-1][k], dp[i][j][k]+pos);
if (all[i]._2 == 0 && k > 0) chmin(dp[i+1][j][k-1], dp[i][j][k]+pos);
// .
chmin(dp[i+1][j][k], dp[i][j][k] + cost[i]);
}
}
}
return dp[N][0][0];
}
Compilation message
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:24:3: error: 'sort' was not declared in this scope
sort(all(all));
^~~~
wiring.cpp:24:3: note: suggested alternative: 'qsort'
sort(all(all));
^~~~
qsort
wiring.cpp:44:26: warning: unused variable 'color' [-Wunused-variable]
int pos = all[i]._1, color = all[i]._2;
^~~~~