이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL INF = 1e9;
const LL LINF = 1e18;
const int N = 2e3+10;
LL dp[N][N][2][2];
LL n,m;
vector<LL>R,B;
LL solve(int i,int j,int t1,int t2){
if(i==n-1&&j==m-1&&t1&&t2)
return 0;
if(dp[i][j][t1][t2]!=-1)
return dp[i][j][t1][t2];
dp[i][j][t1][t2] = LINF;
if(t1&&i<n-1)
dp[i][j][t1][t2] = min(dp[i][j][t1][t2],solve(i+1,j,0,t2));
if(t2&&j<m-1)
dp[i][j][t1][t2] = min(dp[i][j][t1][t2],solve(i,j+1,t1,0));
dp[i][j][t1][t2] = min(dp[i][j][t1][t2],solve(i,j,1,1)+abs(R[i]-B[j]));
return dp[i][j][t1][t2];
}
long long min_total_length(std::vector<int> r, std::vector<int> b) {
n = r.size(),m = b.size();
LL ret = 0;
for(LL i=0;i<n-1;i++)
ret += (r[i+1]-r[i])*(i+1);
for(LL i=m-1;i>=1;i--)
ret += (b[i]-b[i-1])*(m-i);
ret += (b[0]-r[n-1])*min(n,m);
if(n>m)
for(int i=n-1;i>=m;i--)
ret += b[0]-r[i];
if(m>n)
for(int i=0;i<m-n;i++)
ret += b[i]-r[n-1];
return ret;
}
# | 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... |