#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
long long min_total_length(vector<int> r, vector<int> b){
int n=r.size(),m=b.size();
int minn=min(n,m);
if(n*m <= 100000000){
int dp[210][210];
dp[0][0]=abs(r[0]-b[0]);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
int minn=2147483647;
if(i&&j) minn=min(minn,dp[i-1][j-1]);
if(i) minn=min(minn,dp[i-1][j]);
if(j) minn=min(minn,dp[i][j-1]);
minn+=abs(r[i]-b[j]);
if(i||j) dp[i][j]=minn;
}
return dp[n-1][m-1];
}
long long ans=0;
for(int i=0;i<minn;i++)
ans+=b[m-i-1]-r[i];
for(int i=minn;i<n;i++)
ans+=b[0]-r[i];
for(int i=minn;i<m;i++)
ans+=b[m-i-1]-r[n-1];
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
512 KB |
Output is correct |
13 |
Correct |
2 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
16 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
28 ms |
2852 KB |
Output is correct |
4 |
Correct |
28 ms |
2860 KB |
Output is correct |
5 |
Correct |
30 ms |
2908 KB |
Output is correct |
6 |
Correct |
35 ms |
3804 KB |
Output is correct |
7 |
Correct |
39 ms |
3856 KB |
Output is correct |
8 |
Correct |
44 ms |
3832 KB |
Output is correct |
9 |
Correct |
34 ms |
3812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Incorrect |
37 ms |
3804 KB |
3rd lines differ - on the 1st token, expected: '1068938599', found: '-303948787415' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
26 ms |
3192 KB |
3rd lines differ - on the 1st token, expected: '373710605', found: '2074975518' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
512 KB |
Output is correct |
13 |
Correct |
2 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
16 |
Correct |
2 ms |
512 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
28 ms |
2852 KB |
Output is correct |
20 |
Correct |
28 ms |
2860 KB |
Output is correct |
21 |
Correct |
30 ms |
2908 KB |
Output is correct |
22 |
Correct |
35 ms |
3804 KB |
Output is correct |
23 |
Correct |
39 ms |
3856 KB |
Output is correct |
24 |
Correct |
44 ms |
3832 KB |
Output is correct |
25 |
Correct |
34 ms |
3812 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Incorrect |
37 ms |
3804 KB |
3rd lines differ - on the 1st token, expected: '1068938599', found: '-303948787415' |
29 |
Halted |
0 ms |
0 KB |
- |