#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <map>
#include <utility>
#include <vector>
#include "wiring.h"
using namespace std;
map < pair < int ,int > , long long > DP;
long long F(int N,int M,vector < int > &r,vector < int > &b)
{
if(N==0&&M==0) return abs(r[N]-b[M]);
else
{
if(DP.find(make_pair(N,M))!=DP.end()) return DP[make_pair(N,M)];
long long t=abs(r[N]-b[M]),x=1e18;
if(N) x=min(x,F(N-1,M,r,b));
if(M) x=min(x,F(N,M-1,r,b));
if(N&&M) x=min(x,F(N-1,M-1,r,b));
//printf("%d %d %lld\n",N,M,t+x);
DP[make_pair(N,M)]=t+x;
return t+x;
}
}
long long min_total_length(vector < int > r, vector < int > b)
{
int N=r.size();
int M=b.size();
int i;
long long ans=0;
//if(N<=200&&M<=200) return F(N-1,M-1,r,b);
for(i=0;i<N;i++) ans+=abs(r[i]-b[0]);
for(i=0;i<M;i++) ans+=abs(b[i]-r[N-1]);
ans-=abs(b[0]-r[N-1]);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
3rd lines differ - on the 1st token, expected: '25859', found: '50230' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
3rd lines differ - on the 1st token, expected: '904', found: '946' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
3rd lines differ - on the 1st token, expected: '316', found: '356' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
3rd lines differ - on the 1st token, expected: '27', found: '136' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
3rd lines differ - on the 1st token, expected: '25859', found: '50230' |
2 |
Halted |
0 ms |
0 KB |
- |