이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define INF 1e9
#define pb push_back
#define fi first
#define se second
#define sz size()
//===================//
// begin program //
//===================//
const int MX = 5e5;
vii all;
bitset<MX> connected;
int n, m, N;
ll dp[MX];
int gd(int i, int j) {
return abs(all[i].fi - all[j].fi);
}
ll getCost(int x, int y) {
ll ans = 0;
int R=0, B=0;
REI(i,x,y) {
if(all[i].se == all[x].se) {
R++;
} else {
B++;
}
}
if(R < B) {
RE(i,R) ans += gd(x+i, x+R-1);
RE(i,B) ans += gd(y-i, x+R-1);
} else {
RE(i,B) ans += gd(y-i, y-B+1);
RE(i,R) ans += gd(x+i, y-B+1);
}
return ans;
}
long long min_total_length(std::vector<int> r, std::vector<int> b) {
ll ans = 0;
n = r.sz, m = b.sz;
N = n+m;
{
int i=0, j=0;
while(i != n || j != m) {
if(j == m || (i != n && r[i] < b[j])) {
all.pb({r[i++], 0});
} else {
all.pb({b[j++], 1});
}
}
}
// subtask 1 and 2
dp[0] = 0;
REP(i,1,N+1) {
dp[i] = INF;
}
return getCost(0, N-1);
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:59:8: warning: unused variable 'ans' [-Wunused-variable]
ll ans = 0;
^~~
# | 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... |