이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#include "shortcut.h"
using namespace std;
#pragma warning(disable:4996)
typedef long long ll;
typedef long double ld;
ll pos[1000100] = {0};
ll leftPos, rightPos;
bool CanShortcut(ll shortLen, int n, std::vector<int> d, int c)
{
int leftConnectIdx, rightConnectIdx;
// 맨 왼쪽에서 shortLen으로 갈수있는 최대인 곳
for (rightConnectIdx = 0; rightConnectIdx < n; rightConnectIdx++)
{
if (pos[rightConnectIdx] + d[rightConnectIdx] - leftPos > shortLen)
break;
}
if (rightConnectIdx >= n) rightConnectIdx = n - 1;
for (leftConnectIdx = n - 1; leftConnectIdx >= 0; leftConnectIdx--)
{
if (rightPos - (pos[leftConnectIdx] - d[leftConnectIdx]) > shortLen)
break;
}
if (leftConnectIdx < 0) leftConnectIdx = 0;
if (leftConnectIdx >= rightConnectIdx)
return false;
//leftPos-> leftConnect->rightConnect->rightPos
ll newMaxLen = (pos[leftConnectIdx] - leftPos) + c + (rightPos - pos[rightConnectIdx]);
return newMaxLen <= shortLen;
}
long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c)
{
//n--;
leftPos = rightPos = 0;
for (int i = 0; i < n; i++)
{
if (i < n - 1) pos[i + 1] = pos[i] + l[i];
leftPos = min(leftPos, pos[i] - d[i]);
rightPos = max(rightPos, pos[i] + d[i]);
}
ll s = 1, e = rightPos*2, mid;
while (s + 1 < e)
{
mid = (s + e) / 2;
// mid는 가능
if (CanShortcut(mid, n, d, c))
e = mid;
//mid는 불가능
else
s = mid + 1;
}
if (s != e && CanShortcut(s, n, d, c))
e = s;
return min(rightPos - leftPos, e);
}
컴파일 시 표준 에러 (stderr) 메시지
shortcut.cpp:5: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
5 | #pragma warning(disable:4996)
|
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |