이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5+10;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
ll min_total_length(vector<int> r, vector<int> b) {
int n=(int)r.size(), m=(int)b.size();
if(n>m){
swap(n, m);
swap(r, b);
}
r.pb(-1e9-2);
ll ans=0;
int last=0;
for(int i=0;i<n;i++){
int low=last+1, high=m-n+i, best=last;
while(low<=high){
int mid=(low+high)>>1;
if(abs(b[mid]-r[i])<=abs(b[mid]-r[i+1])){
best=mid;
low=mid+1;
}
else high=mid-1;
}
while(last<=best){
ans+=abs(b[last]-r[i]);
last++;
}
}
return ans;
}
# | 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... |