# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
996559 |
2024-06-10T19:33:36 Z |
Edu175 |
Wiring (IOI17_wiring) |
C++17 |
|
62 ms |
25024 KB |
#include "wiring.h"
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(ll i=a,ioi=b;i<ioi;i++)
#define forr(i,a,b) for(ll i=b-1,ioi=a;i>=ioi;i--)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define imp(v) {for(auto dfhg:v)cout<<dfhg<<" ";cout<<"\n";}
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const ll MAXN=2e5+5,INF=1e15;
#define NEUT INF
#define oper min
struct STree{
vector<ll>t; ll n;
STree(ll n):t(2*n+5,NEUT),n(n){}
void upd(ll p, ll v){
for(p+=n,t[p]=v;p>1;p>>=1)t[p>>1]=oper(t[p],t[p^1]);
}
ll query(ll l, ll r){
ll res=NEUT;
for(l+=n,r+=n;l<r;l>>=1,r>>=1){
if(l&1)res=oper(res,t[l++]);
if(r&1)res=oper(res,t[--r]);
}
return res;
}
};
ll n,is[MAXN],d[MAXN];
long long min_total_length(vector<int> a, vector<int> b){
vector<ii>h;
for(auto i:a)h.pb({i,0});
for(auto i:b)h.pb({i,1});
sort(ALL(h));
n=SZ(h);
fore(i,0,n)is[i]=h[i].snd,d[i]=h[i].fst;
vector<ll>l(n+1),r(n+1); r[n]=n;
fore(i,0,n){
if(!i||is[i]!=is[i-1])l[i]=i;
else l[i]=l[i-1];
}
forr(i,0,n){
if(i==n-1||is[i]!=is[i+1])r[i]=i+1;
else r[i]=r[i+1];
}
vector<ll>sp(n+1);//,ps(n+1);
fore(i,1,n+1)sp[i]=sp[i-1]+d[i-1];
// forr(i,0,n)ps[i]=ps[i+1]+d[i];
STree small(n),big(n);
vector<ll>abr(n+5,INF),cer(n+5,INF);
abr[n]=0;
// fore(i,0,n)cout<<i<<": "<<is[i]<<" "<<d[i]<<": "<<l[i]<<" "<<r[i]<<"\n";
// imp(sp);
forr(i,0,n){
ll c=r[i]-i;
ll sl=sp[r[i]]-sp[i]-(r[i]-i)*d[i];
sl=(d[r[i]-1]-d[i])*c-sl;
// ll sl=ps[i]-ps[r[i]]-
ll dis=d[r[i]]-d[r[i]-1];
ll s=r[i],m=r[i]+c,e=r[r[i]];
m=min(m,e);
ll go0=sl+dis*c+small.query(s,m);
ll go1=sl-dis*r[i]+big.query(m,e);
abr[i]=min(go0,go1);
ll sr=sp[i+1]-sp[l[i]]-(i+1-l[i])*d[l[i]];
cer[i]=sr+min(abr[i],abr[i+1]);
small.upd(i,cer[i]);
ll disl=d[l[i]]-(l[i]?d[l[i]-1]:0);
big.upd(i,disl*(i+1)+cer[i]);
// cout<<i<<":\n";
// cout<<s<<" "<<m<<" "<<e<<" sme\n";
// cout<<sl<<" "<<sr<<" sl,sr\n"<<go0<<" "<<go1<<" go\n"<<disl<<" "<<dis<<" dis\n"<<abr[i]<<" "<<cer[i]<<" abr,cer\n\n";
}
return abr[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
34 ms |
18700 KB |
Output is correct |
4 |
Correct |
32 ms |
19376 KB |
Output is correct |
5 |
Correct |
33 ms |
18628 KB |
Output is correct |
6 |
Correct |
53 ms |
24740 KB |
Output is correct |
7 |
Correct |
46 ms |
24256 KB |
Output is correct |
8 |
Correct |
47 ms |
24220 KB |
Output is correct |
9 |
Correct |
46 ms |
24264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2468 KB |
Output is correct |
3 |
Correct |
48 ms |
24068 KB |
Output is correct |
4 |
Correct |
48 ms |
23744 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
0 ms |
2392 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2392 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
45 ms |
24136 KB |
Output is correct |
19 |
Correct |
48 ms |
24492 KB |
Output is correct |
20 |
Correct |
59 ms |
24252 KB |
Output is correct |
21 |
Correct |
48 ms |
24200 KB |
Output is correct |
22 |
Correct |
47 ms |
24396 KB |
Output is correct |
23 |
Correct |
49 ms |
24208 KB |
Output is correct |
24 |
Correct |
46 ms |
24096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
51 ms |
23656 KB |
Output is correct |
3 |
Correct |
44 ms |
24252 KB |
Output is correct |
4 |
Correct |
54 ms |
23488 KB |
Output is correct |
5 |
Correct |
47 ms |
24508 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
55 ms |
23812 KB |
Output is correct |
19 |
Correct |
56 ms |
23496 KB |
Output is correct |
20 |
Correct |
56 ms |
23496 KB |
Output is correct |
21 |
Correct |
62 ms |
24352 KB |
Output is correct |
22 |
Correct |
51 ms |
23488 KB |
Output is correct |
23 |
Correct |
46 ms |
23532 KB |
Output is correct |
24 |
Correct |
49 ms |
23472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2512 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
34 ms |
18700 KB |
Output is correct |
20 |
Correct |
32 ms |
19376 KB |
Output is correct |
21 |
Correct |
33 ms |
18628 KB |
Output is correct |
22 |
Correct |
53 ms |
24740 KB |
Output is correct |
23 |
Correct |
46 ms |
24256 KB |
Output is correct |
24 |
Correct |
47 ms |
24220 KB |
Output is correct |
25 |
Correct |
46 ms |
24264 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
0 ms |
2468 KB |
Output is correct |
28 |
Correct |
48 ms |
24068 KB |
Output is correct |
29 |
Correct |
48 ms |
23744 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
31 |
Correct |
0 ms |
2392 KB |
Output is correct |
32 |
Correct |
0 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
0 ms |
2392 KB |
Output is correct |
35 |
Correct |
0 ms |
2396 KB |
Output is correct |
36 |
Correct |
0 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
0 ms |
2396 KB |
Output is correct |
39 |
Correct |
0 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
0 ms |
2396 KB |
Output is correct |
43 |
Correct |
45 ms |
24136 KB |
Output is correct |
44 |
Correct |
48 ms |
24492 KB |
Output is correct |
45 |
Correct |
59 ms |
24252 KB |
Output is correct |
46 |
Correct |
48 ms |
24200 KB |
Output is correct |
47 |
Correct |
47 ms |
24396 KB |
Output is correct |
48 |
Correct |
49 ms |
24208 KB |
Output is correct |
49 |
Correct |
46 ms |
24096 KB |
Output is correct |
50 |
Correct |
0 ms |
2396 KB |
Output is correct |
51 |
Correct |
51 ms |
23656 KB |
Output is correct |
52 |
Correct |
44 ms |
24252 KB |
Output is correct |
53 |
Correct |
54 ms |
23488 KB |
Output is correct |
54 |
Correct |
47 ms |
24508 KB |
Output is correct |
55 |
Correct |
0 ms |
2396 KB |
Output is correct |
56 |
Correct |
0 ms |
2396 KB |
Output is correct |
57 |
Correct |
0 ms |
2396 KB |
Output is correct |
58 |
Correct |
0 ms |
2396 KB |
Output is correct |
59 |
Correct |
1 ms |
2396 KB |
Output is correct |
60 |
Correct |
0 ms |
2396 KB |
Output is correct |
61 |
Correct |
0 ms |
2396 KB |
Output is correct |
62 |
Correct |
1 ms |
2396 KB |
Output is correct |
63 |
Correct |
0 ms |
2396 KB |
Output is correct |
64 |
Correct |
0 ms |
2396 KB |
Output is correct |
65 |
Correct |
0 ms |
2396 KB |
Output is correct |
66 |
Correct |
1 ms |
2396 KB |
Output is correct |
67 |
Correct |
55 ms |
23812 KB |
Output is correct |
68 |
Correct |
56 ms |
23496 KB |
Output is correct |
69 |
Correct |
56 ms |
23496 KB |
Output is correct |
70 |
Correct |
62 ms |
24352 KB |
Output is correct |
71 |
Correct |
51 ms |
23488 KB |
Output is correct |
72 |
Correct |
46 ms |
23532 KB |
Output is correct |
73 |
Correct |
49 ms |
23472 KB |
Output is correct |
74 |
Correct |
44 ms |
24508 KB |
Output is correct |
75 |
Correct |
49 ms |
23748 KB |
Output is correct |
76 |
Correct |
49 ms |
24508 KB |
Output is correct |
77 |
Correct |
54 ms |
23752 KB |
Output is correct |
78 |
Correct |
50 ms |
24008 KB |
Output is correct |
79 |
Correct |
49 ms |
24468 KB |
Output is correct |
80 |
Correct |
52 ms |
23496 KB |
Output is correct |
81 |
Correct |
44 ms |
23996 KB |
Output is correct |
82 |
Correct |
43 ms |
23752 KB |
Output is correct |
83 |
Correct |
41 ms |
23984 KB |
Output is correct |
84 |
Correct |
40 ms |
24252 KB |
Output is correct |
85 |
Correct |
51 ms |
25024 KB |
Output is correct |
86 |
Correct |
52 ms |
24264 KB |
Output is correct |
87 |
Correct |
50 ms |
24348 KB |
Output is correct |
88 |
Correct |
49 ms |
24252 KB |
Output is correct |
89 |
Correct |
50 ms |
24252 KB |
Output is correct |
90 |
Correct |
56 ms |
24796 KB |
Output is correct |
91 |
Correct |
45 ms |
24864 KB |
Output is correct |
92 |
Correct |
50 ms |
24256 KB |
Output is correct |
93 |
Correct |
51 ms |
24764 KB |
Output is correct |
94 |
Correct |
50 ms |
24108 KB |
Output is correct |
95 |
Correct |
56 ms |
24300 KB |
Output is correct |
96 |
Correct |
48 ms |
24260 KB |
Output is correct |
97 |
Correct |
50 ms |
25020 KB |
Output is correct |
98 |
Correct |
51 ms |
24264 KB |
Output is correct |
99 |
Correct |
50 ms |
24124 KB |
Output is correct |
100 |
Correct |
52 ms |
24256 KB |
Output is correct |
101 |
Correct |
50 ms |
24264 KB |
Output is correct |
102 |
Correct |
52 ms |
25020 KB |
Output is correct |