This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
#include "wiring.h"
const int maxn = 222;
ll dp[maxn][maxn];
vector <pii> pos;
long long min_total_length(std::vector<int> r, std::vector<int> b) {
memset(dp,inf,sizeof(dp));
ll tmp = dp[0][0];
pos.pb({0,-1});
rep(i,0,SZ(r)) pos.pb({r[i],0});
rep(i,0,SZ(b)) pos.pb({b[i],1});
sort(ALL(pos));
int cnt = 0;
rep(i,1,SZ(pos)) if (pos[i].se!=pos[i-1].se) cnt++;
int cur = 1;
int lstsz = 0;
dp[0][0] = 0;
rep(i,1,cnt+1) {
int p = cur;
ll pre = 0;
while (p<SZ(pos) and pos[p].se==pos[cur].se) pre += pos[p].fi,p++;
ll sum = 0;
if (i==1) dp[i][p-cur] = -pre;
else {
rep(j,0,p-cur+1) {
int k = 0;
while (k<=lstsz) {
if (dp[i-1][k]!=tmp) {
if (k<=p-cur-j) dp[i][j] = min(dp[i][j],dp[i-1][k] + pre - sum - 1ll*(p-cur-j-k)*pos[cur-1].fi);
else dp[i][j] = min(dp[i][j],dp[i-1][k] + pre - sum + 1ll*(k-p+cur+j) * pos[cur].fi);
}
k++;
}
sum += pos[p-1-j].fi;
pre -= pos[p-1-j].fi;
// cout<<i<<' '<<j<<' '<<dp[i][j]<<endl;//
}
}
lstsz = p-cur;
cur = p;
}
return dp[cnt][0];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |