| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 337788 | blue | 전선 연결 (IOI17_wiring) | C++11 | 0 ms | 0 KiB |
이 제출은 이전 버전의 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();
int rightend[m];
for(int j = 0; j < m-1; j++) rightend[j] = j;
rightend[m-1] = n-1;
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++) res += abs(r[i] - b[0]);
for(int j = 0; j < m; j++)
{
for(int i = rightend[j-1]+1; i <= rightend[j]; i++) res += abs(r[i] - b[j]);
}
return res;
}
