#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_DIVERGENCE = 50;
const long long INF = 1e15;
long long min_total_length(vector<int> r, vector<int> b) {
vector<pair<int,int>> arr;
for(int&i:b)arr.emplace_back(i,0);
for(int&i:r)arr.emplace_back(i,1);
sort(arr.begin(), arr.end());
int n = arr.size();
arr.insert(arr.begin(),{false,-1});
vector DP(n+1,vector(2,vector(MAX_DIVERGENCE+1,INF)));
DP[0][0][0]=DP[0][1][0]=0;
for(int i=1;i<=n;i++) {
auto [idx,mycolour] = arr[i];
int oppocolour = mycolour^1;
DP[i][oppocolour][MAX_DIVERGENCE]=INF;
for(int j=MAX_DIVERGENCE-1;j>=0;j--) {
DP[i][oppocolour][j]=min(DP[i-1][oppocolour][j+1]+idx,DP[i][oppocolour][j+1]+idx);
}
DP[i][mycolour][0]=DP[i][oppocolour][0];
for(int j=1;j<=MAX_DIVERGENCE;j++) {
DP[i][mycolour][j]=min(DP[i-1][mycolour][j-1]-idx,DP[i][mycolour][j-1]-idx);
}
}
return DP[n][0][0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
0 ms |
604 KB |
3rd lines differ - on the 1st token, expected: '445668', found: '1000000000410628' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
604 KB |
3rd lines differ - on the 1st token, expected: '84383', found: '1000000000045874' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
133 ms |
185212 KB |
Output is correct |
4 |
Correct |
133 ms |
185024 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
436 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
600 KB |
Output is correct |
18 |
Correct |
129 ms |
184984 KB |
Output is correct |
19 |
Correct |
131 ms |
184768 KB |
Output is correct |
20 |
Correct |
143 ms |
185192 KB |
Output is correct |
21 |
Correct |
146 ms |
184768 KB |
Output is correct |
22 |
Correct |
132 ms |
185000 KB |
Output is correct |
23 |
Correct |
132 ms |
185028 KB |
Output is correct |
24 |
Correct |
168 ms |
185040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
126 ms |
184676 KB |
3rd lines differ - on the 1st token, expected: '373710605', found: '1000000009998775' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
0 ms |
604 KB |
3rd lines differ - on the 1st token, expected: '445668', found: '1000000000410628' |
8 |
Halted |
0 ms |
0 KB |
- |