이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <vector>
#include <stack>
#include <algorithm>
#include <assert.h>
#define ll long long
#define pii pair<int, int>
#define fst first
#define snd second
using namespace std;
const int INF = 1e9 + 7;
stack<pii> S;
ll ret = 0;
ll min_total_length(vector<int> r, vector<int> b)
{
assert(r.size() == b.size());
int i = 0, j = 0;
while (i < r.size() || j < b.size())
{
int valL = (i < r.size()) ? r[i] : INF;
int valR = (j < b.size()) ? b[j] : INF;
if (valL < valR)
{
if (S.size() && S.top().snd) {ret += valL - S.top().fst; S.pop();}
else {S.push({valL, 0});}
i++;
}
else
{
if (S.size() && !S.top().snd) {ret += valR - S.top().fst; S.pop();}
else {S.push({valR, 1});}
j++;
}
}
while (S.size())
{
int add = INF;
if (S.top().snd)
{
auto it = upper_bound(r.begin(), r.end(), S.top().fst);
if (it != r.end()) {add = min(add, *it - S.top().fst);}
if (it != r.begin()) {add = min(add, S.top().fst - *prev(it));}
}
else
{
auto it = upper_bound(b.begin(), b.end(), S.top().fst);
if (it != b.end()) {add = min(add, *it - S.top().fst);}
if (it != b.begin()) {add = min(add, S.top().fst - *prev(it));}
}
S.pop(); ret += add;
}
return ret;
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:23:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | while (i < r.size() || j < b.size())
| ~~^~~~~~~~~~
wiring.cpp:23:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | while (i < r.size() || j < b.size())
| ~~^~~~~~~~~~
wiring.cpp:25:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | int valL = (i < r.size()) ? r[i] : INF;
| ~~^~~~~~~~~~
wiring.cpp:26:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | int valR = (j < b.size()) ? b[j] : INF;
| ~~^~~~~~~~~~
# | 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... |