이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
using namespace std;
long long min_total_length(vector<int> r, vector<int> b)
{
if(r.size() < b.size()) swap(r, b);
//assert(r.size() >= b.size());
long long res = 0;
int n = r.size(), m = b.size();
//cout << n << ' ' << m << '\n';
int rightend[m];
for(int j = 0; j < m-1; j++) rightend[j] = j;
rightend[m-1] = n-1;
//cout << rightend[0] << '\n';
for(int j = m-2; j >= 0; j--)
{
while(rightend[j+1] - rightend[j] > 1 && abs(r[rightend[j]+1] - b[j]) <= abs(r[rightend[j]+1] - b[j+1]))
rightend[j]++;
}
for(int i = 0; i <= rightend[0]; i++)
{
//cout << r[i] << ' ' << abs(r[i] - b[0]) << '\n';
res += abs(r[i] - b[0]);
}
for(int j = 1; j < m; j++)
{
for(int i = rightend[j-1]+1; i <= rightend[j]; i++) res += abs(r[i] - b[j]);
}
return res;
}
# | 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... |