제출 #1257491

#제출 시각아이디문제언어결과실행 시간메모리
1257491ThylOneWiring (IOI17_wiring)C++20
13 / 100
21 ms4280 KiB
#include "wiring.h" #include <bits/stdc++.h> using namespace std; long long min_total_length(std::vector<int> r, std::vector<int> b) { vector<pair<int, bool>> boxes; for(auto red:r)boxes.emplace_back(red,false); for(auto blue:b)boxes.emplace_back(blue, true); sort(boxes.begin(), boxes.end(), [](auto a, auto b){return a.first < b.first;}); auto f = [&](){ long long ans = 0; stack<pair<int,bool>> S; int last[2] = {-1,-1}; for(int i = 0;i < boxes.size() ; i++){ last[boxes[i].second] = boxes[i].first; if(S.empty()){ S.push(boxes[i]); }else if(S.top().second != boxes[i].second){ ans += abs(boxes[i].first - S.top().first); S.pop(); }else{ S.push(boxes[i]); } } while(!S.empty()){ ans += abs(S.top().first - last[!S.top().second]); S.pop(); } return ans; }; long long ans = f(); sort(boxes.begin(), boxes.end(), [](auto a, auto b){return a.first > b.first;}); ans = min(ans, f()); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...