이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plll;
typedef pair<pll,pll> ppll;
typedef long double ld;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fst first
#define snd second
#define ins insert
#define pb push_back
template< typename T,typename V>ostream &operator<< (ostream &out,const pair<T,V> x){ out << "{" << x.fst << " : " << x.snd << "}"; return out;}template< typename T>ostream &operator<< (ostream &out,const set<T> x){ for(auto &it : x){ out << it << " "; } return out;}template< typename T>ostream &operator<< (ostream &out,const multiset<T> x){ for(auto &it : x){ out << it << " "; } return out;}template< typename T,typename V>ostream &operator<< (ostream &out,const map<T,V> x){ for(auto &it : x){ out << "[" << it.fst << "]" << " = " << it.snd << "\n"; } return out;}template< typename T>ostream &operator<< (ostream &out,const vector<T> x){ for(int i = 0;i < x.size() - 1; ++i){ out << x[i] << " "; } out << x.back(); return out;}template< typename T>ostream &operator<< (ostream &out,const vector<vector<T> > x){ for(int i = 0;i < x.size() - 1; ++i){ out << "[" << i << "]" << " = {" << x[i] << "}\n"; } out << "[" << x.size() - 1 << "]" << " = {" << x.back() << "}\n"; return out;}
const ll N = 1e6 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e17;
vector<pll> a;
ll dp[N];
long long min_total_length(std::vector<int> r, std::vector<int> b) {
ll n = r.size(),m = b.size();
for(ll i = 0;i < n; ++i){
ll x;
x = r[i];
a.pb({x,0});
}
for(ll i = 0;i < m; ++i){
ll x;
x = b[i];
a.pb({x,1});
}
a.pb({-1,-1});
dp[0] = 0;
sort(all(a));
ll mnb = INF;
ll sumb = 0;
ll cntb = 0;
ll cnta = 0,mxa = 0,suma = 0,id = INF,bsuma = 0,bmxa = 0,bcnta = 0;
for(int i = 1;i < a.size(); ++i){
dp[i] = INF;
if(i == 1 || a[i].snd != a[i - 1].snd){
cntb = 1;
mnb = a[i].fst;
sumb = 0;
cnta = 0,mxa = 0,suma = 0,id = INF;
}else{
sumb += a[i].fst - mnb;
cntb++;
}
int opr = INF;
for(int j = min(i - cntb,id);j > 0; --j){
if(j == id){
opr = 1000;
suma = bsuma;
mxa = bmxa;
cnta = bcnta;
}else{
cnta++;
mxa = max(mxa,a[j].fst);
if(j < i - cntb && a[j].snd != a[j + 1].snd)break;
suma += mxa - a[j].fst;
}
if(dp[j - 1] + sumb + suma + max(cnta,cntb) * (mnb - mxa) < dp[i]){
dp[i] = min(dp[i],dp[j - 1] + sumb + suma + max(cnta,cntb) * (mnb - mxa));
id = j;
bsuma = suma;
bmxa = mxa;
bcnta = cnta;
}else{
if(!opr)break;
opr--;
}
}
for(int j = i - 1;j >= 1; --j){
if(dp[j] <= dp[j + 1])break;
dp[j] = min(dp[j],dp[j + 1]);
}
}
return dp[n + m];
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:42:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1;i < a.size(); ++i){
~~^~~~~~~~~~
wiring.cpp:53:19: warning: overflow in implicit constant conversion [-Woverflow]
int opr = 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... |