# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
895990 |
2023-12-31T11:29:26 Z |
Andrey |
Wiring (IOI17_wiring) |
C++14 |
|
1000 ms |
11688 KB |
#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] = LLONG_MAX/2;
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++) {
| ~~^~~~~~~~~~
# |
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 |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
1081 ms |
8900 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
37 ms |
11688 KB |
Output is correct |
4 |
Correct |
38 ms |
11348 KB |
Output is correct |
5 |
Correct |
0 ms |
544 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 |
432 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
37 ms |
11680 KB |
Output is correct |
19 |
Correct |
37 ms |
11612 KB |
Output is correct |
20 |
Correct |
41 ms |
11576 KB |
Output is correct |
21 |
Correct |
41 ms |
11612 KB |
Output is correct |
22 |
Correct |
39 ms |
11672 KB |
Output is correct |
23 |
Correct |
36 ms |
11664 KB |
Output is correct |
24 |
Correct |
37 ms |
11600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1088 ms |
9756 KB |
Time limit exceeded |
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 |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Execution timed out |
1081 ms |
8900 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |