제출 #1202271

#제출 시각아이디문제언어결과실행 시간메모리
1202271MongHwaWiring (IOI17_wiring)C++20
0 / 100
0 ms328 KiB
#include "wiring.h" using namespace std; #define INF 0x7f7f7f7f bool chk[100005]; long long min_total_length(std::vector<int> r, std::vector<int> b) { int n = (int)r.size(), m = (int)b.size(); long long ans = 0; for(int i = 0; i < n; i++) { int lval = INF, rval = INF, lpos = -1, rpos = -1; auto it = lower_bound(b.begin(), b.end(), r[i]); if(it != b.end()) { rval = *it-r[i]; rpos = it-b.begin(); } if(it != b.begin()) { it = prev(it); lval = r[i]-*it; lpos = it-b.begin(); } if(lval < rval) { ans += lval; chk[lpos] = 1; } else if(lval > rval) { ans += rval; chk[rpos] = 1; } else { ans += lval; if(!chk[lpos] && chk[rpos]) chk[lpos] = 1; else if(chk[lpos] && !chk[rpos]) chk[rpos] = 1; else chk[lpos] = 1; } } for(int i = 0; i < m; i++) { if(chk[i]) continue; int lval = INF, rval = INF; auto it = lower_bound(r.begin(), r.end(), b[i]); if(it != r.end()) rval = *it-b[i]; if(it != r.begin()) { it = prev(it); lval = b[i]-*it; } ans += min(lval, rval); } 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...