이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#include "wiring.h"
const int N = 2e3 + 11;
ll dp[N][N];
ll min_total_length(vector<int> r, vector<int> b){
vector<ll>red, blue;
red.push_back(0);
blue.push_back(0);
for(auto it : r)red.push_back((ll)it);
for(auto it : b)blue.push_back((ll)it);
if(sz(r) <= 200 && sz(b) <= 200){
memset(dp, 0x3f, sizeof(dp));
dp[0][0] = 0;
for(int i = 1; i < sz(red); i++){
for(int j = 1; j < sz(blue); j++){
dp[i][j] = min({dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]}) + abs(red[i] - blue[j]);
}
}
return dp[sz(red) - 1][sz(blue) - 1];
}
ll ans = 0;
if(sz(r) <= sz(b)){
ll point = red[sz(red) - 1];
for(auto it : blue){
ll cur = it - point;
if(cur < 0)cur = -cur;
ans += cur;
}
for(int i = 1; i < sz(red) - 1; i++){
ll cur = red[i] - point;
if(cur < 0)cur = -cur;
ans += cur;
}
}else{
ll point = blue[1];
for(auto it : red){
ll cur = it - point;
if(cur < 0)cur = -cur;
ans += cur;
}
for(int i = 1; i < sz(blue); i++){
ll cur = blue[i] - point;
if(cur < 0)cur = -cur;
ans += cur;
}
}
return ans;
}
# | 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... |