# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
72943 |
2018-08-27T09:23:42 Z |
SmsS |
Wiring (IOI17_wiring) |
C++17 |
|
1000 ms |
7572 KB |
#include<bits/stdc++.h>
using namespace std;
#define for2(a,b,c) for(int a=b;a<c;a++)
#define ll long long
#include "wiring.h"
ll sub2(vector<int> r,vector<int> b){
ll res = 0;
int L = 0;
int R = b.size()-1;
while(L != r.size() && R != -1){
res += b[R]-r[L];
L++;
R--;
}
while(R != -1){
res += b[R]-r[L-1];
R--;
}
while(L != r.size()){
res += b[R+1]-r[L];
L++;
}
return res;
}
#define PII pair<int,int>
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(),(x).end()
const int maxn = 200100;
ll dp[maxn];
ll sub3(vector<int> v1,vector<int> v2){
vector<int> v[2];
vector<PII> V;
for(auto x : v1) {
v[0].pb(x);
V.pb({x,0});
}
for(auto x : v2){
v[1].pb(x);
V.pb({x,1});
}
sort(all(V));
int n = V.size();
for2(i,0,n){
int x = V[i].F;
bool t = V[i].S;
dp[i] = 1e18;
ll tmp = 1e18;
int ind = lower_bound(all(v[!t]),x)-v[!t].begin();
if(ind != v[!t].size()) tmp = min(tmp,(ll)v[!t][ind]-x);
ind --;
if(ind >= 0) tmp = min(tmp,(ll)x-v[!t][ind]);
if(i) tmp += dp[i-1];
dp[i] = tmp;
tmp = 0;
ll cnt = 0;
for(int j = i; j >= 0; j--){
if(j != i) tmp += cnt*(V[j+1].F-V[j].F);
if(V[j].S != V[i].S) break;
cnt++;
}
int k = 0;
for(int j = max(0ll,i-2*cnt+1); j <= i-cnt; j++){
if(V[j].S == V[i].S) break;
if(j != i-2*cnt+1) tmp += k*(V[j].F-V[j-1].F);
k++;
}
if(k != cnt){
continue;
}
dp[i] = min(dp[i],dp[i-2*cnt]+tmp);
}
return dp[V.size()-1];
}
long long min_total_length(std::vector<int> r, std::vector<int> b) {
if(r.back() < b[0]) return sub2(r,b);
return sub3(r,b);
}
Compilation message
wiring.cpp: In function 'long long int sub2(std::vector<int>, std::vector<int>)':
wiring.cpp:11:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(L != r.size() && R != -1){
~~^~~~~~~~~~~
wiring.cpp:20:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(L != r.size()){
~~^~~~~~~~~~~
wiring.cpp: In function 'long long int sub3(std::vector<int>, std::vector<int>)':
wiring.cpp:55:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(ind != v[!t].size()) tmp = min(tmp,(ll)v[!t][ind]-x);
~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
412 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
552 KB |
Output is correct |
7 |
Correct |
2 ms |
560 KB |
Output is correct |
8 |
Correct |
2 ms |
560 KB |
Output is correct |
9 |
Correct |
2 ms |
560 KB |
Output is correct |
10 |
Correct |
2 ms |
560 KB |
Output is correct |
11 |
Correct |
2 ms |
560 KB |
Output is correct |
12 |
Correct |
3 ms |
560 KB |
Output is correct |
13 |
Correct |
2 ms |
560 KB |
Output is correct |
14 |
Correct |
3 ms |
560 KB |
Output is correct |
15 |
Correct |
3 ms |
688 KB |
Output is correct |
16 |
Correct |
3 ms |
688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
688 KB |
Output is correct |
2 |
Correct |
3 ms |
688 KB |
Output is correct |
3 |
Correct |
31 ms |
2376 KB |
Output is correct |
4 |
Correct |
33 ms |
2376 KB |
Output is correct |
5 |
Correct |
33 ms |
2376 KB |
Output is correct |
6 |
Correct |
47 ms |
2936 KB |
Output is correct |
7 |
Correct |
38 ms |
3064 KB |
Output is correct |
8 |
Correct |
41 ms |
3064 KB |
Output is correct |
9 |
Correct |
40 ms |
3064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3064 KB |
Output is correct |
2 |
Correct |
3 ms |
3064 KB |
Output is correct |
3 |
Correct |
93 ms |
7364 KB |
Output is correct |
4 |
Correct |
78 ms |
7364 KB |
Output is correct |
5 |
Correct |
2 ms |
7364 KB |
Output is correct |
6 |
Correct |
3 ms |
7364 KB |
Output is correct |
7 |
Correct |
2 ms |
7364 KB |
Output is correct |
8 |
Correct |
3 ms |
7364 KB |
Output is correct |
9 |
Correct |
2 ms |
7364 KB |
Output is correct |
10 |
Correct |
2 ms |
7364 KB |
Output is correct |
11 |
Correct |
2 ms |
7364 KB |
Output is correct |
12 |
Correct |
2 ms |
7364 KB |
Output is correct |
13 |
Correct |
3 ms |
7364 KB |
Output is correct |
14 |
Correct |
3 ms |
7364 KB |
Output is correct |
15 |
Correct |
2 ms |
7364 KB |
Output is correct |
16 |
Correct |
2 ms |
7364 KB |
Output is correct |
17 |
Correct |
2 ms |
7364 KB |
Output is correct |
18 |
Correct |
80 ms |
7364 KB |
Output is correct |
19 |
Correct |
80 ms |
7364 KB |
Output is correct |
20 |
Correct |
82 ms |
7364 KB |
Output is correct |
21 |
Correct |
82 ms |
7364 KB |
Output is correct |
22 |
Correct |
78 ms |
7364 KB |
Output is correct |
23 |
Correct |
87 ms |
7444 KB |
Output is correct |
24 |
Correct |
85 ms |
7572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7572 KB |
Output is correct |
2 |
Execution timed out |
1075 ms |
7572 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
412 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
552 KB |
Output is correct |
7 |
Correct |
2 ms |
560 KB |
Output is correct |
8 |
Correct |
2 ms |
560 KB |
Output is correct |
9 |
Correct |
2 ms |
560 KB |
Output is correct |
10 |
Correct |
2 ms |
560 KB |
Output is correct |
11 |
Correct |
2 ms |
560 KB |
Output is correct |
12 |
Correct |
3 ms |
560 KB |
Output is correct |
13 |
Correct |
2 ms |
560 KB |
Output is correct |
14 |
Correct |
3 ms |
560 KB |
Output is correct |
15 |
Correct |
3 ms |
688 KB |
Output is correct |
16 |
Correct |
3 ms |
688 KB |
Output is correct |
17 |
Correct |
3 ms |
688 KB |
Output is correct |
18 |
Correct |
3 ms |
688 KB |
Output is correct |
19 |
Correct |
31 ms |
2376 KB |
Output is correct |
20 |
Correct |
33 ms |
2376 KB |
Output is correct |
21 |
Correct |
33 ms |
2376 KB |
Output is correct |
22 |
Correct |
47 ms |
2936 KB |
Output is correct |
23 |
Correct |
38 ms |
3064 KB |
Output is correct |
24 |
Correct |
41 ms |
3064 KB |
Output is correct |
25 |
Correct |
40 ms |
3064 KB |
Output is correct |
26 |
Correct |
2 ms |
3064 KB |
Output is correct |
27 |
Correct |
3 ms |
3064 KB |
Output is correct |
28 |
Correct |
93 ms |
7364 KB |
Output is correct |
29 |
Correct |
78 ms |
7364 KB |
Output is correct |
30 |
Correct |
2 ms |
7364 KB |
Output is correct |
31 |
Correct |
3 ms |
7364 KB |
Output is correct |
32 |
Correct |
2 ms |
7364 KB |
Output is correct |
33 |
Correct |
3 ms |
7364 KB |
Output is correct |
34 |
Correct |
2 ms |
7364 KB |
Output is correct |
35 |
Correct |
2 ms |
7364 KB |
Output is correct |
36 |
Correct |
2 ms |
7364 KB |
Output is correct |
37 |
Correct |
2 ms |
7364 KB |
Output is correct |
38 |
Correct |
3 ms |
7364 KB |
Output is correct |
39 |
Correct |
3 ms |
7364 KB |
Output is correct |
40 |
Correct |
2 ms |
7364 KB |
Output is correct |
41 |
Correct |
2 ms |
7364 KB |
Output is correct |
42 |
Correct |
2 ms |
7364 KB |
Output is correct |
43 |
Correct |
80 ms |
7364 KB |
Output is correct |
44 |
Correct |
80 ms |
7364 KB |
Output is correct |
45 |
Correct |
82 ms |
7364 KB |
Output is correct |
46 |
Correct |
82 ms |
7364 KB |
Output is correct |
47 |
Correct |
78 ms |
7364 KB |
Output is correct |
48 |
Correct |
87 ms |
7444 KB |
Output is correct |
49 |
Correct |
85 ms |
7572 KB |
Output is correct |
50 |
Correct |
2 ms |
7572 KB |
Output is correct |
51 |
Execution timed out |
1075 ms |
7572 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |