#include "wiring.h"
long long abs (long long x){
if (x > 0) return x;
return -x;
}
long long max (long long a, long long b){
if (a > b) return a;
return b;
}
long long min_total_length(std::vector<int> r, std::vector<int> b) {
int n, m;
n = r.size();
m = b.size();
if (r[n-1] < b[0]){
long long ans = 0;
for (int i=0; i<n; i++){
ans += r[n-1] - r[i];
}
for (int i=0; i<m; i++){
ans += b[i] - b[0];
}
ans += max(n, m) *(b[0] - r[n-1]);
return ans;
}
long long DP[n][m];
DP[0][0] = b[0] - r[0];
for (int i=0; i<n; i++){
for (int j=0; j<m; j++){
if (i == 0 && j == 0) continue;
if (i == 0){
DP[i][j] = DP[i][j-1] + abs(r[i] - b[j]);
continue;
}
if (j == 0){
DP[i][j] = DP[i-1][j] + abs(r[i] - b[j]);
continue;
}
DP[i][j] = max(max(DP[i-1][j], DP[i][j-1]), DP[i-1][j-1]) + abs(r[i] - b[j]);
}
}
return DP[n-1][m-1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
1936 KB |
3rd lines differ - on the 1st token, expected: '25859', found: '50230' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1936 KB |
Output is correct |
2 |
Correct |
0 ms |
1936 KB |
Output is correct |
3 |
Correct |
30 ms |
3112 KB |
Output is correct |
4 |
Correct |
30 ms |
3112 KB |
Output is correct |
5 |
Correct |
28 ms |
3112 KB |
Output is correct |
6 |
Correct |
37 ms |
3504 KB |
Output is correct |
7 |
Correct |
37 ms |
3504 KB |
Output is correct |
8 |
Correct |
39 ms |
3504 KB |
Output is correct |
9 |
Correct |
30 ms |
3504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1936 KB |
Output is correct |
2 |
Incorrect |
0 ms |
1936 KB |
3rd lines differ - on the 1st token, expected: '17703', found: '56684' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
1936 KB |
3rd lines differ - on the 1st token, expected: '27', found: '183' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
1936 KB |
3rd lines differ - on the 1st token, expected: '25859', found: '50230' |
2 |
Halted |
0 ms |
0 KB |
- |