# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1049300 |
2024-08-08T16:08:27 Z |
Ahmed57 |
Wiring (IOI17_wiring) |
C++17 |
|
44 ms |
14284 KB |
#include "bits/stdc++.h"
using namespace std;
long long min_total_length(vector<int> r, vector<int> b){
vector<pair<long long,int>> v;
for(auto i:r){
v.push_back({i,0});
}
for(auto i:b){
v.push_back({i,1});
}
sort(v.begin(),v.end());
int n = v.size();
long long pref[n+1] = {0};
for(int i = 0;i<n;i++){
pref[i+1] = v[i].first;
pref[i+1]+=pref[i];
}
int st[n],en[n];
for(int i = 0;i<n;i++){
if(i==0||v[i].second!=v[i-1].second){
st[i] = i;
}else st[i] = st[i-1];
}
for(int i = n-1;i>=0;i--){
if(i==n-1||v[i].second!=v[i+1].second){
en[i] = i;
}else en[i] = en[i+1];
}
long long dp[n+1][2];
for(int i = 0;i<=n;i++)dp[i][0] = dp[i][1] = 1e18;
dp[0][0] = 0;
for(int i = 1;i<=n;i++){
int S = st[i-1];
int E = en[i-1];
if(S==i-1)dp[i][0] = min(dp[i][0],dp[i-1][1]);
int V = i-S;
if(S!=0)dp[i][0] = min(dp[i][0],dp[i-1][0]+abs(v[i-1].first-v[S-1].first));
if(S-V>=0)dp[i][0] = min(dp[i][0],dp[S-V][0]+pref[i]-pref[S]-(pref[S]-pref[S-V]));
if(E<n-1)dp[i][1] = min(dp[i][1],dp[i-1][0]+abs(v[i-1].first-v[E+1].first));
dp[i][0] = min(dp[i][0],dp[i][1]);
}
return dp[n][0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
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 |
432 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 |
440 KB |
Output is correct |
15 |
Correct |
0 ms |
440 KB |
Output is correct |
16 |
Correct |
0 ms |
384 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 |
Correct |
17 ms |
10536 KB |
Output is correct |
4 |
Correct |
17 ms |
10696 KB |
Output is correct |
5 |
Correct |
17 ms |
11128 KB |
Output is correct |
6 |
Correct |
22 ms |
13536 KB |
Output is correct |
7 |
Correct |
23 ms |
13756 KB |
Output is correct |
8 |
Correct |
22 ms |
13256 KB |
Output is correct |
9 |
Correct |
21 ms |
13304 KB |
Output is correct |
# |
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 |
32 ms |
13352 KB |
Output is correct |
4 |
Correct |
31 ms |
13088 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 |
604 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 |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
31 ms |
13732 KB |
Output is correct |
19 |
Correct |
44 ms |
13356 KB |
Output is correct |
20 |
Correct |
33 ms |
13248 KB |
Output is correct |
21 |
Correct |
30 ms |
13232 KB |
Output is correct |
22 |
Correct |
31 ms |
13248 KB |
Output is correct |
23 |
Correct |
32 ms |
13580 KB |
Output is correct |
24 |
Correct |
31 ms |
14012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
29 ms |
12812 KB |
Output is correct |
3 |
Correct |
29 ms |
13344 KB |
Output is correct |
4 |
Correct |
28 ms |
12684 KB |
Output is correct |
5 |
Correct |
29 ms |
13640 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
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 |
432 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
448 KB |
Output is correct |
18 |
Correct |
26 ms |
12704 KB |
Output is correct |
19 |
Correct |
27 ms |
13000 KB |
Output is correct |
20 |
Correct |
28 ms |
12992 KB |
Output is correct |
21 |
Correct |
24 ms |
12732 KB |
Output is correct |
22 |
Correct |
32 ms |
12964 KB |
Output is correct |
23 |
Correct |
22 ms |
12732 KB |
Output is correct |
24 |
Correct |
22 ms |
12836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
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 |
432 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 |
440 KB |
Output is correct |
15 |
Correct |
0 ms |
440 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
17 ms |
10536 KB |
Output is correct |
20 |
Correct |
17 ms |
10696 KB |
Output is correct |
21 |
Correct |
17 ms |
11128 KB |
Output is correct |
22 |
Correct |
22 ms |
13536 KB |
Output is correct |
23 |
Correct |
23 ms |
13756 KB |
Output is correct |
24 |
Correct |
22 ms |
13256 KB |
Output is correct |
25 |
Correct |
21 ms |
13304 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
32 ms |
13352 KB |
Output is correct |
29 |
Correct |
31 ms |
13088 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
604 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
31 ms |
13732 KB |
Output is correct |
44 |
Correct |
44 ms |
13356 KB |
Output is correct |
45 |
Correct |
33 ms |
13248 KB |
Output is correct |
46 |
Correct |
30 ms |
13232 KB |
Output is correct |
47 |
Correct |
31 ms |
13248 KB |
Output is correct |
48 |
Correct |
32 ms |
13580 KB |
Output is correct |
49 |
Correct |
31 ms |
14012 KB |
Output is correct |
50 |
Correct |
0 ms |
344 KB |
Output is correct |
51 |
Correct |
29 ms |
12812 KB |
Output is correct |
52 |
Correct |
29 ms |
13344 KB |
Output is correct |
53 |
Correct |
28 ms |
12684 KB |
Output is correct |
54 |
Correct |
29 ms |
13640 KB |
Output is correct |
55 |
Correct |
1 ms |
344 KB |
Output is correct |
56 |
Correct |
0 ms |
344 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
0 ms |
348 KB |
Output is correct |
62 |
Correct |
0 ms |
348 KB |
Output is correct |
63 |
Correct |
0 ms |
348 KB |
Output is correct |
64 |
Correct |
0 ms |
432 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
0 ms |
448 KB |
Output is correct |
67 |
Correct |
26 ms |
12704 KB |
Output is correct |
68 |
Correct |
27 ms |
13000 KB |
Output is correct |
69 |
Correct |
28 ms |
12992 KB |
Output is correct |
70 |
Correct |
24 ms |
12732 KB |
Output is correct |
71 |
Correct |
32 ms |
12964 KB |
Output is correct |
72 |
Correct |
22 ms |
12732 KB |
Output is correct |
73 |
Correct |
22 ms |
12836 KB |
Output is correct |
74 |
Correct |
23 ms |
13208 KB |
Output is correct |
75 |
Correct |
28 ms |
12988 KB |
Output is correct |
76 |
Correct |
27 ms |
13364 KB |
Output is correct |
77 |
Correct |
26 ms |
13052 KB |
Output is correct |
78 |
Correct |
25 ms |
12736 KB |
Output is correct |
79 |
Correct |
26 ms |
12740 KB |
Output is correct |
80 |
Correct |
22 ms |
13068 KB |
Output is correct |
81 |
Correct |
30 ms |
12732 KB |
Output is correct |
82 |
Correct |
26 ms |
13500 KB |
Output is correct |
83 |
Correct |
25 ms |
13512 KB |
Output is correct |
84 |
Correct |
22 ms |
13356 KB |
Output is correct |
85 |
Correct |
28 ms |
13248 KB |
Output is correct |
86 |
Correct |
23 ms |
14252 KB |
Output is correct |
87 |
Correct |
25 ms |
13256 KB |
Output is correct |
88 |
Correct |
25 ms |
14108 KB |
Output is correct |
89 |
Correct |
26 ms |
13248 KB |
Output is correct |
90 |
Correct |
29 ms |
13256 KB |
Output is correct |
91 |
Correct |
24 ms |
13256 KB |
Output is correct |
92 |
Correct |
27 ms |
13256 KB |
Output is correct |
93 |
Correct |
24 ms |
14264 KB |
Output is correct |
94 |
Correct |
35 ms |
13356 KB |
Output is correct |
95 |
Correct |
38 ms |
14268 KB |
Output is correct |
96 |
Correct |
23 ms |
13244 KB |
Output is correct |
97 |
Correct |
23 ms |
13768 KB |
Output is correct |
98 |
Correct |
26 ms |
13244 KB |
Output is correct |
99 |
Correct |
32 ms |
13584 KB |
Output is correct |
100 |
Correct |
30 ms |
13500 KB |
Output is correct |
101 |
Correct |
29 ms |
14284 KB |
Output is correct |
102 |
Correct |
28 ms |
13500 KB |
Output is correct |