This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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]){
int 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 - m]);
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 - n)){
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... |