이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define fi first
#define se second
const int mxN=1e5;
const ll INF=1e18;
ll p[2*mxN], ps[2*mxN+1], dp[2*mxN+1], mn1[mxN+1]={INF};
ll min_total_length(vector<int> r, vector<int> b) {
int n=r.size()+b.size();
vector<pii> cls;
for(int i=0, ri=0, bi=0, lc=-1, cc; i<n; ++i, lc=cc) {
if(ri>=r.size()||bi<b.size()&&b[bi]<r[ri]) {
p[i]=b[bi++];
cc=0;
} else {
p[i]=r[ri++];
cc=1;
}
ps[i+1]=p[i]+ps[i];
if(cc!=lc)
cls.push_back({i, i});
else
++cls.back().se;
}
for(int i=cls[0].fi; i<=cls[0].se; ++i)
dp[i+1]=INF;
for(int bi=0; bi<cls.size()-1; ++bi) {
for(int i=0; i<=cls[bi].se-cls[bi].fi; ++i)
mn1[i+1]=min(min(dp[i+cls[bi].fi], dp[cls[bi+1].fi])+(cls[bi].se-cls[bi].fi+1-i)*p[cls[bi+1].fi]+ps[cls[bi].fi+i], mn1[i]);
ll mn2=INF;
for(int i=0; i<=cls[bi+1].se-cls[bi+1].fi; ++i) {
dp[i+cls[bi+1].fi+1]=mn2-(i+1)*p[cls[bi].se];
if(i<=cls[bi].se-cls[bi].fi) {
dp[i+cls[bi+1].fi+1]=min(mn1[cls[bi].se-cls[bi].fi+1-i]-(i+1)*p[cls[bi+1].fi], dp[i+cls[bi+1].fi+1]);
mn2=min(min(dp[cls[bi].se-i], dp[cls[bi+1].fi])+(i+1)*p[cls[bi].se]+ps[cls[bi].se-i], mn2);
}
dp[i+cls[bi+1].fi+1]+=ps[cls[bi+1].fi+i+1]-2*ps[cls[bi+1].fi];
}
}
return dp[n];
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:18:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(ri>=r.size()||bi<b.size()&&b[bi]<r[ri]) {
~~^~~~~~~~~~
wiring.cpp:18:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(ri>=r.size()||bi<b.size()&&b[bi]<r[ri]) {
~~^~~~~~~~~
wiring.cpp:18:31: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
if(ri>=r.size()||bi<b.size()&&b[bi]<r[ri]) {
wiring.cpp:33:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int bi=0; bi<cls.size()-1; ++bi) {
~~^~~~~~~~~~~~~
# | 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... |