# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
60578 | Eae02 | Palembang Bridges (APIO15_bridge) | C++14 | 5 ms | 516 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
int main()
{
int numBridges, numPeople;
std::cin >> numBridges;
std::cin >> numPeople;
if (numBridges != 1)
return 1;
uint64_t baseDistSum = 0;
std::vector<std::pair<int, int>> cPeople;
cPeople.reserve(numPeople);
for (int i = 0; i < numPeople; i++)
{
char z1, z2;
int p1, p2;
std::cin >> z1;
std::cin >> p1;
std::cin >> z2;
std::cin >> p2;
if (p1 > p2)
std::swap(p1, p2);
baseDistSum += p2 - p1;
if (z1 != z2)
{
cPeople.emplace_back(p1, p2);
}
}
const int MAX_BEG = 1000000001;
auto MinExtDist = [&] (uint64_t pos) -> uint64_t
{
uint64_t dist = 0;
for (const auto& p : cPeople)
{
if (pos <= p.first)
dist += (p.first - pos) * 2 + 1;
else if (pos >= p.second)
dist += (pos - p.second) * 2 + 1;
else
dist += 1;
}
return dist;
};
#ifdef LOCAL
for (int i = 0; i < 20; i++)
{
std::cout << " " << (baseDistSum + MinExtDist(i));
}
std::cout << std::endl;
#endif
int x;
uint64_t min = 0;
uint64_t max = MAX_BEG;
while (true)
{
uint64_t mid = min + (max - min) / 2;
uint64_t dm = MinExtDist(mid);
#ifdef LOCAL
std::cout << min << ", " << max << ", " << mid << " : " << dm << std::endl;
#endif
if (mid >= MAX_BEG || dm <= MinExtDist(mid + 1))
{
if (mid == 0 || dm <= MinExtDist(mid - 1))
{
x = dm;
break;
}
max = mid + 1;
}
else
{
min = mid;
}
}
std::cout << baseDistSum + x << std::endl;
}
컴파일 시 표준 에러 (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... |