이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int,int> ii;
ll dp[200005], prefixSum[200005], rem[200005];
ll min_total_length(vector<int> r, vector<int> b) {
vector <ii> lst;
int piR = 0, piB = 0;
while(piR < r.size() || piB < b.size()){
if (piR == r.size())
lst.push_back(ii(b[piB++], 2));
else if (piB == b.size())
lst.push_back(ii(r[piR++], 1));
else{
if (r[piR] < b[piB])
lst.push_back(ii(r[piR++], 1));
else
lst.push_back(ii(b[piB++], 2));
}
}
piR = 0, piB = 0;
int slope = 0, lrange = 0, rrange = 0;
r.push_back((int)2e9+5);
b.push_back((int)2e9+5);
for(int i=0;i<lst.size();i++){
dp[i+1] = (ll) 1e18;
prefixSum[i+1] = prefixSum[i] + (lst[i].second == 1 ? 1 : -1) * lst[i].first;
slope += (lst[i].second == 1 ? 1 : -1);
while(r[piR+1] <= lst[i].first) piR++;
while(b[piB+1] <= lst[i].first) piB++;
if (lst[i].second == 1)
dp[i+1] = dp[i] + min(abs(lst[i].first - b[piB]), abs(lst[i].first - b[piB+1]));
else
dp[i+1] = dp[i] + min(abs(lst[i].first - r[piR]), abs(lst[i].first - r[piR+1]));
if (lrange <= slope && slope <= rrange)
dp[i+1] = min(dp[i+1], dp[rem[slope]] + abs(prefixSum[i+1] - prefixSum[rem[slope]]));
lrange = min(lrange, slope);
rrange = max(rrange, slope);
rem[slope] = i+1;
}
return dp[lst.size()];
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:10:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(piR < r.size() || piB < b.size()){
~~~~^~~~~~~~~~
wiring.cpp:10:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(piR < r.size() || piB < b.size()){
~~~~^~~~~~~~~~
wiring.cpp:11:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (piR == r.size())
~~~~^~~~~~~~~~~
wiring.cpp:13:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
else if (piB == b.size())
~~~~^~~~~~~~~~~
wiring.cpp:26:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<lst.size();i++){
~^~~~~~~~~~~
# | 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... |