This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█
#include "wiring.h"
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <cassert>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< lo,lo > PII;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 100000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;
lo n,m,b[li],a[li],k,flag,t,mx,mn=inf,dp[205][205];
lo cev;
queue<lo> q,q1;
map<lo,lo> PS;
string s;
vector<PII> v;
inline lo f(lo l,lo rr,vector<int>r,vector<int>b){
lo cevv=inf;
//~ if(l==n && rr==m-1)return 0;
//~ if(l==n-1 && rr==m)return 0;
if(l==n && rr==m)return 0;
if(l>n || rr>m || (rr==m && l!=n) || (rr!=m && l==n))return inf;
if(~dp[l][rr])return dp[l][rr];
cevv=min(cevv,f(l+1,rr,r,b)+abs(b[rr]-r[l]));
cevv=min(cevv,f(l,rr+1,r,b)+abs(b[rr]-r[l]));
cevv=min(cevv,f(l+1,rr+1,r,b)+abs(b[rr]-r[l]));
return dp[l][rr]=cevv;
}
long long min_total_length(std::vector<int> r, std::vector<int> b) {
if(r.size()<=200 && b.size()<=200){
memset(dp,-1,sizeof(dp));
for(lo i=0;i<(lo)r.size();i++){v.pb(mp(r[i],1));}
for(lo i=0;i<(lo)b.size();i++){v.pb(mp(b[i],2));}
n=r.size();
m=b.size();
return f(0,0,r,b);
}
for(lo i=0;i<(lo)r.size();i++){v.pb(mp(r[i],1));}
for(lo i=0;i<(lo)b.size();i++){v.pb(mp(b[i],2));}
sort(v.begin(),v.end());
for(int i=0;i<(int)v.size();i++){
if(v[i].se==1)q.push(v[i].fi);
else{
if(q.size()){
cev+=abs(v[i].fi-q.front());
mx=max(mx,q.front());
q.pop();
}
else cev+=abs(v[i].fi-mx);
mn=min(mn,v[i].fi);
}
}
while(q.size()){cev+=abs(mn-q.front());q.pop();}
return cev;
}
# | 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... |