이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "wiring.h"
#define mk make_pair
#define sc second
#define fr first
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )
#define Scan(a) scanf ("%I64d", &a)
#define scan(a) scanf ("%d", &a)
using namespace std;
const long long INF = (int)1e18 + 7;
const int N = (int)1e5 + 12;
const int mod = 1000000007;
int dp[1111][1111] , red[N], blue[N];
long long min_total_length(std::vector<int > r, std::vector<int > b){
int n = r.size(), m = b.size();
for(int i = 1;i <= n; i++){
red[i] = r[i - 1];
}
for(int i = 1;i <= m; i++){
blue[i] = b[i - 1];
}
if(red[n] < blue[1]){
long long ans = 0;
if(n >= m){
for(int i = 1;i <= m; i++){
ans += abs(blue[i] - red[n - i + 1]);
}
int i = m;
while((n - i)){
ans += abs(blue[1] - red[n - i]);
i++;
}
return ans;
}
else{
for(int i = 1;i <= n; i++){
ans += abs(blue[i] - red[n - i + 1]);
}
int i = n + 1;
while((m - i)){
ans += abs(blue[i] - red[n]);
i++;
}
return ans;
}
}
else{
memset(dp,0x3f3f3f3f,sizeof(dp));
dp[0][0] = 0;
for(int i = 1;i <= n; i++){
for(int j = 1;j <= m; j++){
dp[i][j] = min({dp[i - 1][j - 1],dp[i - 1][j],dp[i][j - 1]}) + abs(red[i] - blue[j]);
}
}
return dp[n][m];
}
}
# | 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... |