제출 #637318

#제출 시각아이디문제언어결과실행 시간메모리
637318boris_mihovWiring (IOI17_wiring)C++17
13 / 100
49 ms8488 KiB
#include "wiring.h" #include <algorithm> #include <iostream> #include <numeric> #include <vector> #include <set> typedef long long llong; const int MAXN = 100000 + 10; std::set <int> s; long long min_total_length(std::vector <int> r, std::vector <int> b) { std::sort(r.begin(), r.end()); std::sort(b.begin(), b.end()); if (r.size() > b.size()) std::swap(r, b); for (const int &i : b) { s.insert(i); } llong ans = 0; for (const int &i : r) { auto it = s.upper_bound(i); auto left = it; left--; if (it == s.end()) { ans += abs(*left - i); s.erase(left); } else if (left == s.end()) { ans += abs(*it - i); s.erase(it); } else { if (abs(*left - i) <= abs(*it - i)) { ans += abs(*left - i); s.erase(left); } else { ans += abs(*it - i); s.erase(it); } } } int ptr = 0; for (const int &i : s) { while (ptr + 1 != r.size() && r[ptr + 1] <= i) ptr++; int currMin = abs(i - r[ptr]); if (ptr + 1 != r.size()) currMin = std::min(currMin, abs(r[ptr + 1] - i)); ans += currMin; } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:53:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         while (ptr + 1 != r.size() && r[ptr + 1] <= i) ptr++;
      |                ~~~~~~~~^~~~~~~~~~~
wiring.cpp:55:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         if (ptr + 1 != r.size()) currMin = std::min(currMin, abs(r[ptr + 1] - i));
      |             ~~~~~~~~^~~~~~~~~~~
#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...