이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define INF 1e9
#define pb push_back
#define fi first
#define se second
#define sz size()
ll min_total_length(std::vector<int> r, std::vector<int> b) {
int n = r.sz, m = b.sz;
int i=0, j=0;
ll ans = 0;
while(i < n && j < m) {
ans += abs(r[i] - b[j]);
i++; j++;
}
while(i < n) {
int lb = lower_bound(b.begin(), b.end(), r[i])-b.begin()-1;
int mn = INF;
RE(x,2) {
int y=lb+x;
if(y < 0 || y >= m) continue;
mn = min(mn, r[i] - b[y]);
}
ans += mn;
i++;
}
while(j < m) {
int lb = lower_bound(r.begin(), r.end(), b[j])-r.begin()-1;
int mn = INF;
RE(x,2) {
int y=lb+x;
if(y < 0 || y >= n) continue;
mn = min(mn, b[j] - r[y]);
}
ans += mn;
j++;
}
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... |