# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
953180 |
2024-03-25T15:55:55 Z |
pragma |
Wiring (IOI17_wiring) |
C++14 |
|
90 ms |
36904 KB |
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
const int inf = 1234567890;
typedef pair<int, int> pi;
typedef long long lint;
int n;
pi a[1000005];
set<int> sa, sb;
int getnear(int x){
int ret = 2e9;
if(a[x].second == 1){
auto p = sa.lower_bound(a[x].first);
if(p != sa.end()){
ret = min(ret, *p - a[x].first);
}
if(p != sa.begin()){
p--;
ret = min(ret, a[x].first - *p);
}
}
else{
auto p = sb.lower_bound(a[x].first);
if(p != sb.end()){
ret = min(ret, *p - a[x].first);
}
if(p != sb.begin()){
p--;
ret = min(ret, a[x].first - *p);
}
}
return ret;
}
lint suma[1000005], sumb[1000005];
lint dp[1000005];
int mat[1000005], prv[2000005];
long long min_total_length(std::vector<int> aa, std::vector<int> bb) {
int p = aa.size();
int q = bb.size();
for(int i=1; i<=p; i++){
a[i].first = aa[i-1];
sa.insert(aa[i-1]);
a[i].second = -1;
}
for(int i=1; i<=q; i++){
a[i+p].first = bb[i-1];
sb.insert(bb[i-1]);
a[i+p].second = 1;
}
n = p+q;
sort(a+1, a+n+1);
memset(mat, -1, sizeof(mat));
memset(prv, -1, sizeof(prv));
prv[n] = 0;
int cur = n;
for(int i=1; i<=n; i++){
suma[i] = suma[i-1];
sumb[i] = sumb[i-1];
if(a[i].second == -1){
suma[i] += a[i].first;
cur++;
}
else{
sumb[i] += a[i].first;
cur--;
}
if(prv[cur] >= 0){
mat[i] = prv[cur];
}
prv[cur] = i;
}
for(int i=1; i<=n; i++){
dp[i] = dp[i-1] + getnear(i);
if(~mat[i]){
dp[i] = min(dp[i], dp[mat[i]] + abs(suma[i] - suma[mat[i]] - sumb[i] + sumb[mat[i]]));
}
}
return dp[n];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14940 KB |
Output is correct |
2 |
Correct |
2 ms |
14940 KB |
Output is correct |
3 |
Correct |
2 ms |
14936 KB |
Output is correct |
4 |
Correct |
3 ms |
14940 KB |
Output is correct |
5 |
Correct |
2 ms |
14940 KB |
Output is correct |
6 |
Correct |
2 ms |
14940 KB |
Output is correct |
7 |
Correct |
2 ms |
14940 KB |
Output is correct |
8 |
Correct |
2 ms |
14940 KB |
Output is correct |
9 |
Correct |
3 ms |
14940 KB |
Output is correct |
10 |
Correct |
2 ms |
14940 KB |
Output is correct |
11 |
Correct |
3 ms |
14940 KB |
Output is correct |
12 |
Correct |
3 ms |
14940 KB |
Output is correct |
13 |
Correct |
3 ms |
14940 KB |
Output is correct |
14 |
Correct |
3 ms |
14940 KB |
Output is correct |
15 |
Correct |
3 ms |
14940 KB |
Output is correct |
16 |
Correct |
2 ms |
14940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14940 KB |
Output is correct |
2 |
Correct |
2 ms |
14940 KB |
Output is correct |
3 |
Correct |
51 ms |
30840 KB |
Output is correct |
4 |
Correct |
46 ms |
30840 KB |
Output is correct |
5 |
Correct |
53 ms |
31056 KB |
Output is correct |
6 |
Correct |
64 ms |
36436 KB |
Output is correct |
7 |
Correct |
64 ms |
36444 KB |
Output is correct |
8 |
Correct |
65 ms |
36656 KB |
Output is correct |
9 |
Correct |
64 ms |
36436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14936 KB |
Output is correct |
2 |
Correct |
2 ms |
14936 KB |
Output is correct |
3 |
Correct |
81 ms |
36624 KB |
Output is correct |
4 |
Correct |
79 ms |
36276 KB |
Output is correct |
5 |
Correct |
3 ms |
14936 KB |
Output is correct |
6 |
Correct |
2 ms |
14940 KB |
Output is correct |
7 |
Correct |
2 ms |
14940 KB |
Output is correct |
8 |
Correct |
3 ms |
14784 KB |
Output is correct |
9 |
Correct |
2 ms |
14936 KB |
Output is correct |
10 |
Correct |
2 ms |
14940 KB |
Output is correct |
11 |
Correct |
2 ms |
14940 KB |
Output is correct |
12 |
Correct |
2 ms |
14936 KB |
Output is correct |
13 |
Correct |
2 ms |
14940 KB |
Output is correct |
14 |
Correct |
3 ms |
14940 KB |
Output is correct |
15 |
Correct |
2 ms |
14940 KB |
Output is correct |
16 |
Correct |
3 ms |
14940 KB |
Output is correct |
17 |
Correct |
2 ms |
14940 KB |
Output is correct |
18 |
Correct |
90 ms |
36416 KB |
Output is correct |
19 |
Correct |
80 ms |
36620 KB |
Output is correct |
20 |
Correct |
80 ms |
36580 KB |
Output is correct |
21 |
Correct |
81 ms |
36436 KB |
Output is correct |
22 |
Correct |
81 ms |
36460 KB |
Output is correct |
23 |
Correct |
83 ms |
36436 KB |
Output is correct |
24 |
Correct |
80 ms |
36436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14936 KB |
Output is correct |
2 |
Correct |
80 ms |
35928 KB |
Output is correct |
3 |
Correct |
75 ms |
35924 KB |
Output is correct |
4 |
Correct |
76 ms |
35828 KB |
Output is correct |
5 |
Correct |
74 ms |
35964 KB |
Output is correct |
6 |
Correct |
2 ms |
14972 KB |
Output is correct |
7 |
Correct |
2 ms |
14940 KB |
Output is correct |
8 |
Correct |
2 ms |
14940 KB |
Output is correct |
9 |
Correct |
2 ms |
14940 KB |
Output is correct |
10 |
Correct |
2 ms |
14940 KB |
Output is correct |
11 |
Correct |
2 ms |
14940 KB |
Output is correct |
12 |
Correct |
2 ms |
14940 KB |
Output is correct |
13 |
Correct |
3 ms |
14940 KB |
Output is correct |
14 |
Correct |
3 ms |
15196 KB |
Output is correct |
15 |
Correct |
2 ms |
14940 KB |
Output is correct |
16 |
Correct |
3 ms |
14936 KB |
Output is correct |
17 |
Correct |
2 ms |
14940 KB |
Output is correct |
18 |
Correct |
69 ms |
35776 KB |
Output is correct |
19 |
Correct |
70 ms |
35956 KB |
Output is correct |
20 |
Correct |
68 ms |
35984 KB |
Output is correct |
21 |
Correct |
67 ms |
35892 KB |
Output is correct |
22 |
Correct |
67 ms |
35852 KB |
Output is correct |
23 |
Correct |
64 ms |
35924 KB |
Output is correct |
24 |
Correct |
66 ms |
35928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14940 KB |
Output is correct |
2 |
Correct |
2 ms |
14940 KB |
Output is correct |
3 |
Correct |
2 ms |
14936 KB |
Output is correct |
4 |
Correct |
3 ms |
14940 KB |
Output is correct |
5 |
Correct |
2 ms |
14940 KB |
Output is correct |
6 |
Correct |
2 ms |
14940 KB |
Output is correct |
7 |
Correct |
2 ms |
14940 KB |
Output is correct |
8 |
Correct |
2 ms |
14940 KB |
Output is correct |
9 |
Correct |
3 ms |
14940 KB |
Output is correct |
10 |
Correct |
2 ms |
14940 KB |
Output is correct |
11 |
Correct |
3 ms |
14940 KB |
Output is correct |
12 |
Correct |
3 ms |
14940 KB |
Output is correct |
13 |
Correct |
3 ms |
14940 KB |
Output is correct |
14 |
Correct |
3 ms |
14940 KB |
Output is correct |
15 |
Correct |
3 ms |
14940 KB |
Output is correct |
16 |
Correct |
2 ms |
14940 KB |
Output is correct |
17 |
Correct |
3 ms |
14940 KB |
Output is correct |
18 |
Correct |
2 ms |
14940 KB |
Output is correct |
19 |
Correct |
51 ms |
30840 KB |
Output is correct |
20 |
Correct |
46 ms |
30840 KB |
Output is correct |
21 |
Correct |
53 ms |
31056 KB |
Output is correct |
22 |
Correct |
64 ms |
36436 KB |
Output is correct |
23 |
Correct |
64 ms |
36444 KB |
Output is correct |
24 |
Correct |
65 ms |
36656 KB |
Output is correct |
25 |
Correct |
64 ms |
36436 KB |
Output is correct |
26 |
Correct |
2 ms |
14936 KB |
Output is correct |
27 |
Correct |
2 ms |
14936 KB |
Output is correct |
28 |
Correct |
81 ms |
36624 KB |
Output is correct |
29 |
Correct |
79 ms |
36276 KB |
Output is correct |
30 |
Correct |
3 ms |
14936 KB |
Output is correct |
31 |
Correct |
2 ms |
14940 KB |
Output is correct |
32 |
Correct |
2 ms |
14940 KB |
Output is correct |
33 |
Correct |
3 ms |
14784 KB |
Output is correct |
34 |
Correct |
2 ms |
14936 KB |
Output is correct |
35 |
Correct |
2 ms |
14940 KB |
Output is correct |
36 |
Correct |
2 ms |
14940 KB |
Output is correct |
37 |
Correct |
2 ms |
14936 KB |
Output is correct |
38 |
Correct |
2 ms |
14940 KB |
Output is correct |
39 |
Correct |
3 ms |
14940 KB |
Output is correct |
40 |
Correct |
2 ms |
14940 KB |
Output is correct |
41 |
Correct |
3 ms |
14940 KB |
Output is correct |
42 |
Correct |
2 ms |
14940 KB |
Output is correct |
43 |
Correct |
90 ms |
36416 KB |
Output is correct |
44 |
Correct |
80 ms |
36620 KB |
Output is correct |
45 |
Correct |
80 ms |
36580 KB |
Output is correct |
46 |
Correct |
81 ms |
36436 KB |
Output is correct |
47 |
Correct |
81 ms |
36460 KB |
Output is correct |
48 |
Correct |
83 ms |
36436 KB |
Output is correct |
49 |
Correct |
80 ms |
36436 KB |
Output is correct |
50 |
Correct |
3 ms |
14936 KB |
Output is correct |
51 |
Correct |
80 ms |
35928 KB |
Output is correct |
52 |
Correct |
75 ms |
35924 KB |
Output is correct |
53 |
Correct |
76 ms |
35828 KB |
Output is correct |
54 |
Correct |
74 ms |
35964 KB |
Output is correct |
55 |
Correct |
2 ms |
14972 KB |
Output is correct |
56 |
Correct |
2 ms |
14940 KB |
Output is correct |
57 |
Correct |
2 ms |
14940 KB |
Output is correct |
58 |
Correct |
2 ms |
14940 KB |
Output is correct |
59 |
Correct |
2 ms |
14940 KB |
Output is correct |
60 |
Correct |
2 ms |
14940 KB |
Output is correct |
61 |
Correct |
2 ms |
14940 KB |
Output is correct |
62 |
Correct |
3 ms |
14940 KB |
Output is correct |
63 |
Correct |
3 ms |
15196 KB |
Output is correct |
64 |
Correct |
2 ms |
14940 KB |
Output is correct |
65 |
Correct |
3 ms |
14936 KB |
Output is correct |
66 |
Correct |
2 ms |
14940 KB |
Output is correct |
67 |
Correct |
69 ms |
35776 KB |
Output is correct |
68 |
Correct |
70 ms |
35956 KB |
Output is correct |
69 |
Correct |
68 ms |
35984 KB |
Output is correct |
70 |
Correct |
67 ms |
35892 KB |
Output is correct |
71 |
Correct |
67 ms |
35852 KB |
Output is correct |
72 |
Correct |
64 ms |
35924 KB |
Output is correct |
73 |
Correct |
66 ms |
35928 KB |
Output is correct |
74 |
Correct |
62 ms |
36432 KB |
Output is correct |
75 |
Correct |
78 ms |
36400 KB |
Output is correct |
76 |
Correct |
69 ms |
36656 KB |
Output is correct |
77 |
Correct |
67 ms |
36128 KB |
Output is correct |
78 |
Correct |
69 ms |
35916 KB |
Output is correct |
79 |
Correct |
84 ms |
35856 KB |
Output is correct |
80 |
Correct |
69 ms |
35904 KB |
Output is correct |
81 |
Correct |
68 ms |
35924 KB |
Output is correct |
82 |
Correct |
64 ms |
35920 KB |
Output is correct |
83 |
Correct |
63 ms |
36180 KB |
Output is correct |
84 |
Correct |
63 ms |
36436 KB |
Output is correct |
85 |
Correct |
74 ms |
36656 KB |
Output is correct |
86 |
Correct |
65 ms |
36432 KB |
Output is correct |
87 |
Correct |
69 ms |
36432 KB |
Output is correct |
88 |
Correct |
67 ms |
36432 KB |
Output is correct |
89 |
Correct |
67 ms |
36852 KB |
Output is correct |
90 |
Correct |
71 ms |
36632 KB |
Output is correct |
91 |
Correct |
66 ms |
36512 KB |
Output is correct |
92 |
Correct |
77 ms |
36432 KB |
Output is correct |
93 |
Correct |
70 ms |
36692 KB |
Output is correct |
94 |
Correct |
68 ms |
36628 KB |
Output is correct |
95 |
Correct |
70 ms |
36440 KB |
Output is correct |
96 |
Correct |
72 ms |
36508 KB |
Output is correct |
97 |
Correct |
65 ms |
36436 KB |
Output is correct |
98 |
Correct |
73 ms |
36904 KB |
Output is correct |
99 |
Correct |
69 ms |
36496 KB |
Output is correct |
100 |
Correct |
71 ms |
36436 KB |
Output is correct |
101 |
Correct |
64 ms |
36420 KB |
Output is correct |
102 |
Correct |
69 ms |
36624 KB |
Output is correct |