#include <bits/stdc++.h>
#include <bits/extc++.h>
#define starburststream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define ef(a) emplace_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define f first
#define s second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define tomax(a, b) ((a) = max((a), (b)))
#define tomin(a, b) ((a) = min((a), (b)))
#define topos(a) ((a) = (((a) % mod + mod) % mod))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
if(pvaspace) b << " "; pvaspace=true;\
b << pva;\
}\
b << "\n";}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;
const ll mod = 1000000007;
const ll max = 2147483647;
template<typename a, typename b>
ostream& operator<<(ostream& o, pair<a, b> p){
return o << '(' << p.f << ',' << p.s << ')';
}
ll ifloor(ll a, ll b){
if(b < 0) a *= -1, b *= -1;
if(a < 0) return (a - b + 1) / b;
else return a / b;
}
ll iceil(ll a, ll b){
if(b < 0) a *= -1, b *= -1;
if(a > 0) return (a + b - 1) / b;
else return a / b;
}
void waassert(bool b){
if(b) return;
cout << "wa\n";
exit(0);
}
using pdd = pair<ld, ld>;
ld eps = 1e-9;
pdd operator+(pdd a, pdd b){
return mp(a.f + b.f, a.s + b.s);
}
pdd operator-(pdd a, pdd b){
return mp(a.f - b.f, a.s - b.s);
}
ld dot(pdd a, pdd b){
return a.f * b.f + a.s * b.s;
}
ld cross(pdd a, pdd b){
return a.f * b.s - a.s * b.f;
}
ld abs2(pdd a){
return a.f * a.f + a.s * a.s;
}
ld abs(pdd a){
return sqrt(abs2(a));
}
pdd operator*(ld i, pdd p){
return mp(i * p.f, i * p.s);
}
int ori(pdd a, pdd b){
if(abs(cross(a, b)) <= eps) return 0;
else if(cross(a, b) > 0) return 1;
else return -1;
}
bool intersect(pdd a, pdd b, pdd c, pdd d){
return ori(b - a, c - a) * ori(b - a, d - a) < 0 && ori(d - c, a - c) * ori(d - c, b - c) < 0;
}
bool canproj(pdd p, pdd a, pdd b){
return dot(b - a, p - a) >= 0 && dot(a - b, p - b) >= 0;
}
pdd getproj(pdd p, pdd a, pdd b){
if(abs2(a - b) <= eps) return a;
return a + dot(p - a, b - a) / abs2(b - a) * (b - a);
}
pdd v1 = mp(0, 0), v2 = mp(48763, 3234234);
struct line{
pdd a, b;
};
struct edge{
int to;
ld w;
int f;
};
ostream& operator<<(ostream& o, edge e){
return o << '(' << e.to << ',' << e.w << ',' << e.f << ')';
}
int n;
ld s;
vector<line> border;
vector<line> e;
vector<pdd> pos;
vector<vector<int>> ps;
vector<vector<edge>> g;
map<pdd, int> vid;
int ts;
void init(){
cin >> n >> s;
e.resize(n);
for(int i = 0; i < n; i++){
cin >> e[i].a.f >> e[i].a.s >> e[i].b.f >> e[i].b.s;
}
border.eb(line({mp(s, s), mp(s, -s)}));
border.eb(line({mp(-s, -s), mp(s, -s)}));
border.eb(line({mp(-s, -s), mp(-s, s)}));
border.eb(line({mp(s, s), mp(-s, s)}));
border.eb(line({mp(s, -s), mp(-s, s)}));
border.eb(line({mp(-s, -s), mp(s, s)}));
e.eb(line({mp(s, s), mp(s, s)}));
e.eb(line({mp(s, -s), mp(s, -s)}));
e.eb(line({mp(-s, s), mp(-s, s)}));
e.eb(line({mp(-s, -s), mp(-s, -s)}));
n += 4;
ps.resize(n);
}
bool check(pdd a, pdd b){
for(auto i : border){
if(intersect(a, b, i.a, i.b)) return false;
}
return true;
}
int getv(pdd p){
if(vid.find(p) != vid.end()) return vid[p];
vid[p] = ts++;
pos.eb(p);
g.eb();
return vid[p];
}
bool foxyy(pdd a, pdd b){
return intersect(a, b, v1, v2);
}
void addedge(int x, pdd a, int y, pdd b){
if(!check(a, b)){
//cerr << "qq " << a << " " << b << "\n";
return;
}
int av = getv(a);
int bv = getv(b);
//cerr << "addedge " << x << " " << av << " " << y << " " << bv << "\n";
ps[x].eb(av); ps[y].eb(bv);
g[av].eb(edge({bv, abs(a - b), foxyy(a, b)}));
g[bv].eb(edge({av, abs(a - b), foxyy(a, b)}));
//cerr << "addedge " << a << " " << b << " " << abs(a - b) << " " << foxyy(a, b) << "\n";
}
void tryproj(int x, pdd p, int y, pdd a, pdd b){
if(!canproj(p, a, b)) return;
//cerr << "canproj " << x << " " << p << " " << y << " " << getproj(p, a, b) << "\n";
addedge(x, p, y, getproj(p, a, b));
}
void buildedges(int x, int y){
addedge(x, e[x].a, y, e[y].a);
addedge(x, e[x].b, y, e[y].a);
addedge(x, e[x].a, y, e[y].b);
addedge(x, e[x].b, y, e[y].b);
tryproj(x, e[x].a, y, e[y].a, e[y].b);
tryproj(x, e[x].b, y, e[y].a, e[y].b);
tryproj(y, e[y].a, x, e[x].a, e[x].b);
tryproj(y, e[y].b, x, e[x].a, e[x].b);
}
void buildline(int id){
sort(iter(ps[id]), [&](int x, int y){
return pos[x] < pos[y];
});
uni(ps[id]);
for(int i = 0; i + 1 < ps[id].size(); i++){
int x = ps[id][i], y = ps[id][i + 1];
g[x].eb(edge({y, 0, foxyy(pos[x], pos[y])}));
g[y].eb(edge({x, 0, foxyy(pos[x], pos[y])}));
}
}
struct info{
ld d;
int v;
int f;
bool operator<(info b) const{
return d > b.d;
}
};
ld calc(int s){
std::priority_queue<info> pq;
vector<vector<ld>> dis(2, vector<ld>(ts, 1e20));
dis[0][s] = 0;
pq.push(info({0, s, 0}));
vector<vector<bool>> vst(2, vector<bool>(ts));
int cnt = 0;
while(!pq.empty()){
ld d = pq.top().d;
int v = pq.top().v, f = pq.top().f;
pq.pop();
if(vst[f][v] || abs(d - dis[f][v]) > eps) continue;
vst[f][v] = true;
for(auto i : g[v]){
int nf = f ^ i.f;
cnt++;
assert(cnt <= 1e4);
if(vst[nf][i.to] || d + i.w >= dis[nf][i.to] - eps) continue;
dis[nf][i.to] = d + i.w;
pq.push(info({d + i.w, i.to, nf}));
}
}
//cerr << "calc " << s << " " << dis[1][s] << "\n";
return dis[1][s];
}
int main(){
starburststream
init();
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++) buildedges(i, j);
}
for(int i = 0; i < n; i++) buildline(i);
/*cerr << "graph\n";
for(int i = 0; i < ts; i++){
cerr << i << " " << pos[i] << " ";
printv(g[i], cerr);
}*/
ld ans = 1e20;
for(int i = 0; i < ts; i++){
ans = min(ans, calc(i));
}
cout << fixed << setprecision(20) << ans << "\n";
return 0;
}
Compilation message
fences.cpp: In function 'void buildline(int)':
fences.cpp:221:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
221 | for(int i = 0; i + 1 < ps[id].size(); i++){
| ~~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
276 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
2 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
204 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
41 |
Correct |
1 ms |
204 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
276 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
2 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
204 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
41 |
Correct |
1 ms |
204 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Runtime error |
14 ms |
5952 KB |
Execution killed with signal 6 |
45 |
Halted |
0 ms |
0 KB |
- |