| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 79111 | Plurm | Wiring (IOI17_wiring) | C++11 | 2 ms | 508 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <vector>
#include <algorithm>
using namespace std;
long long min_total_length(vector<int> r, vector<int> b) {
vector<pair<int,bool> > combined;
vector<long long> qs;
for(int x : r){
combined.emplace_back(x,false);
}
for(int x : b){
combined.emplace_back(x,true);
}
sort(combined.begin(),combined.end());
bool cur = !combined.front().second;
int clen = 0;
int llen = 0;
int begin = 0;
vector<int> lpos;
lpos.resize(combined.size());
vector<int> laxis;
laxis.resize(combined.size());
for(int i = 0; i < combined.size(); i++){
if(combined[i].second == cur){
clen++;
}else{
begin = i;
llen = clen;
clen = 1;
cur = !cur;
}
lpos[i] = 2*begin-i-1;
laxis[i] = begin;
if(lpos[i] < begin-llen){
lpos[i] = -1;
}
}
qs.push_back(combined.front().first);
for(int i = 1; i < combined.size(); i++){
qs.push_back(qs.back() + (long long)combined[i].first);
}
vector<long long> dp;
dp.resize(combined.size());
for(int i = 1; i < combined.size(); i++){
// Case 1: dp[i] = dp[i-1] + abs(pos[i] - pos[j])
if(combined[i].second){
auto it = lower_bound(r.begin(),r.end(),combined[i].first);
if(it == r.begin()){
dp[i] = 1e18;
}else{
dp[i] = dp[i-1] + combined[i].first - *(it-1);
if(it != r.end())
dp[i] = min(dp[i],dp[i-1] + *it - combined[i].first);
}
}else{
auto it = lower_bound(b.begin(),b.end(),combined[i].first);
if(it == b.begin()){
dp[i] = 1e18;
}else{
dp[i] = dp[i-1] + combined[i].first - *(it-1);
if(it != b.end())
dp[i] = min(dp[i],dp[i-1] - combined[i].first + *it);
}
}
// Case 2: dp[i] = dp[j] + Distance Differences
if(lpos[i] != -1){
dp[i] = min(dp[i],qs[i] - qs[laxis[i]-1] - qs[laxis[i]-1] + qs[lpos[i]-1] + dp[lpos[i]-1]);
}
}
return dp.back();
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
