#include "wiring.h"
#include<bits/stdc++.h>
using namespace std;
long long min_total_length(std::vector<int> r, std::vector<int> b) {
long long n = r.size(),m = b.size();
vector<pair<long long,long long>> haha(n+m+1,{-1,-1});
for(long long i = 0; i < r.size(); i++) {
haha[i] = {r[i],0};
}
for(long long i = 0; i < m; i++) {
haha[i+n] = {b[i],1};
}
sort(haha.begin(),haha.end());
vector<long long> wow(n+m+1);
vector<long long> wut(n+m+1);
long long c = 0,sb = 0;
for(long long i = 1; i <= n+m; i++) {
if(i > 1 && haha[i].second != haha[i-1].second) {
c = haha[i].first;
sb = 0;
}
sb+=haha[i].first-c;
wow[i] = sb;
}
c = haha[n+m].first,sb = 0;
for(long long i = n+m; i >= 1; i--) {
if(i < n+m && haha[i].second != haha[i+1].second) {
c = haha[i].first;
sb = 0;
}
sb+=c-haha[i].first;
wut[i] = sb;
}
vector<long long> dp(n+m+1);
long long l = -1;
for(long long i = 1; i <= n+m; i++) {
if(i != 1 && haha[i].second != haha[i-1].second) {
l = i-1;
}
dp[i] = 1000;
long long y = l;
while(y >= 0 && (y == l || haha[y+1].second == haha[l].second)) {
dp[i] = min(dp[i],wow[i]+wut[min(l,y+1)]+dp[y]+(haha[l+1].first-haha[l].first)*max(l-y,i-l));
y--;
}
}
return dp[n+m];
}
Compilation message
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:8:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | for(long long i = 0; i < r.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
3rd lines differ - on the 1st token, expected: '25859', found: '1000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '84383', found: '1000' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '17703', found: '1000' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
440 KB |
Output is correct |
2 |
Execution timed out |
1043 ms |
10932 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
3rd lines differ - on the 1st token, expected: '25859', found: '1000' |
2 |
Halted |
0 ms |
0 KB |
- |