# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
529463 |
2022-02-23T03:43:42 Z |
8e7 |
Fences (JOI18_fences) |
C++17 |
|
59 ms |
1720 KB |
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ...b ){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 420
#define pii pair<double, double>
#define eps 1e-9
#define x first
#define y second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
pii vec(pii p, pii q) {return {q.x - p.x, q.y - p.y};}
pii operator *(pii p, double x) {return {p.x * x, p.y * x};}
pii operator +(pii p, pii q){return {p.x + q.x, p.y + q.y};}
double dot(pii p, pii q){return p.x * q.x + p.y * q.y;}
double cross(pii p, pii q){return p.x * q.y - p.y * q.x;}
int sgn(double x){return (x > eps ? 1 : (x > -eps ? 0 : -1));}
bool inl(pii p, pii l1, pii l2) {
return abs(cross(vec(p, l1), vec(p, l2))) <= eps && dot(vec(p, l1), vec(p, l2)) <= eps;
}
bool inter(pii p1, pii p2, pii q1, pii q2) {
if (inl(p1, q1, q2) || inl(p2, q1, q2) || inl(q1, p1, p2) || inl(q2, p1, p2)) return 1;
if (sgn(cross(vec(p1, q1), vec(p1, q2))) != sgn(cross(vec(p2, q1), vec(p2, q2))) &&
sgn(cross(vec(q1, p1), vec(q1, p2))) != sgn(cross(vec(q2, p1), vec(q2, p2)))) return 1;
return 0;
}
double sd(pii p, pii q){return (q.x - p.x) * (q.x - p.x) + (q.y - p.y) * (q.y - p.y);}
pii getpnt(pii p, pii l1, pii l2) {
pii vi = vec(l1, l2);
if (sgn(dot(vi, vec(l1, p))) * sgn(dot(vi, vec(l2, p))) != 1) {
double len = dot(vec(l1, p), vi) / sd(l1, l2);
return l1 + (vi*len);
} else {
if (sd(p, l1) < sd(p, l2)) return l1;
else return l2;
}
}
double dis(pii p, pii l1, pii l2) {
return sqrt(sd(p, getpnt(p, l1, l2)));
}
pii edge[4];
bool valid(pii p, pii q) {
bool op[4], oq[4];
int pc = 0, qc = 0;
for (int i = 0;i < 4;i++) {
op[i] = inl(p, edge[i], edge[(i+1)%4]);
oq[i] = inl(q, edge[i], edge[(i+1)%4]);
pc += op[i] ? 1 : 0, qc += oq[i] ? 1 : 0;
}
if (pc && qc) {
for (int i = 0;i < 4;i++) {
if (op[i] && oq[i]) return 1;
}
return 0;
} else {
for (int i = 0;i < 4;i++) {
if (inter(p, q, edge[i], edge[(i+1)%4])) {
if (!op[i] && !oq[i]) return 0;
}
}
return 1;
}
}
const pii ray0 = {0, 0}, ray1 = {maxn, 1};
pii a[maxn];
const double inf = 1e9;
double g[maxn][maxn];
int main() {
io
int n, s;
cin >> n >> s;
for (int i = 0;i < n;i++) {
cin >> a[2*i].x >> a[2*i].y >> a[2*i+1].x >> a[2*i+1].y;
}
edge[0] = {s, s}, edge[1] = {s, -s}, edge[2] = {-s, -s}, edge[3] = {-s, s};
/*
pii test;
cin >> test.x >> test.y;
cout << dis(test, a[4], a[5]) << endl;
*/
int m = 4 * n + 8;
for (int i = 0;i < m;i++) {
for (int j = 0;j < m;j++) g[i][j] = inf;
g[i][i] = 0;
}
double ans = 8 * s;
auto chmin = [&](double &x, double d){x = min(x, d);};
auto addedge = [&](int i, int j, double d, bool type) {
if (type) {
chmin(g[i*2][j*2+1], d);
chmin(g[j*2+1][i*2], d);
chmin(g[i*2+1][j*2], d);
chmin(g[j*2][i*2+1], d);
} else {
chmin(g[i*2][j*2], d);
chmin(g[j*2][i*2], d);
chmin(g[i*2+1][j*2+1], d);
chmin(g[j*2+1][i*2+1], d);
}
};
auto change = [&](pii p, pii q) {return inter(p, q, ray0, ray1);};
for (int i = 0;i < 2 * n;i++) {
for (int j = 0;j < 2 * n;j++) {
if (i == j) continue;
if (i % 2 == 0 && j == i+1) {
addedge(i, j, 0, change(a[i], a[j]));
} else {
pii best;
if (j % 2) best = getpnt(a[i], a[j], a[j-1]);
else best = getpnt(a[i], a[j], a[j+1]);
if (valid(a[i], best)) {
addedge(i, j, sqrt(sd(best, a[i])), change(a[i], best) ^ change(best, a[j]));
}
}
}
if (i % 2 == 0) {
for (int j = 0;j < 4;j++) {
pii best = getpnt(edge[j], a[i], a[i+1]);
if (valid(edge[j], best)) {
addedge(2*n+j, i, sqrt(sd(edge[j], best)), change(edge[j], best) ^ change(best, a[i]));
}
}
}
}
for (int i = 0;i < 4;i++) {
addedge(2*n+i, 2*n+(i+1)%4, 2*s, change(edge[i], edge[(i+1)%4]));
}
for (int k = 0;k < m;k++) {
for (int i = 0;i < m;i++) {
for (int j = 0;j < m;j++) {
g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
}
}
}
for (int i = 0;i < m;i+=2) {
ans = min(ans, g[i][i+1]);
debug(i, g[i][i+1]);
}
/*
int qu, qv;
while (cin >> qu >> qv) {
debug("same: ", g[qu*2][qv*2]);
debug("dif: ", g[qu*2][qv*2+1]);
}
*/
cout << fixed << setprecision(10) << ans << endl;
}
Compilation message
fences.cpp: In function 'int main()':
fences.cpp:12:20: warning: statement has no effect [-Wunused-value]
12 | #define debug(...) 0
| ^
fences.cpp:157:3: note: in expansion of macro 'debug'
157 | debug(i, g[i][i+1]);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
0 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 |
320 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
0 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
316 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
0 ms |
332 KB |
Output is correct |
43 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
0 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 |
320 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
0 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
316 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
0 ms |
332 KB |
Output is correct |
43 |
Correct |
0 ms |
332 KB |
Output is correct |
44 |
Correct |
59 ms |
1612 KB |
Output is correct |
45 |
Correct |
52 ms |
1612 KB |
Output is correct |
46 |
Correct |
50 ms |
1648 KB |
Output is correct |
47 |
Correct |
50 ms |
1612 KB |
Output is correct |
48 |
Correct |
52 ms |
1612 KB |
Output is correct |
49 |
Correct |
51 ms |
1612 KB |
Output is correct |
50 |
Correct |
50 ms |
1660 KB |
Output is correct |
51 |
Correct |
58 ms |
1656 KB |
Output is correct |
52 |
Correct |
50 ms |
1612 KB |
Output is correct |
53 |
Correct |
50 ms |
1648 KB |
Output is correct |
54 |
Correct |
51 ms |
1612 KB |
Output is correct |
55 |
Correct |
52 ms |
1612 KB |
Output is correct |
56 |
Correct |
52 ms |
1644 KB |
Output is correct |
57 |
Correct |
51 ms |
1612 KB |
Output is correct |
58 |
Correct |
53 ms |
1660 KB |
Output is correct |
59 |
Correct |
59 ms |
1612 KB |
Output is correct |
60 |
Correct |
51 ms |
1612 KB |
Output is correct |
61 |
Correct |
50 ms |
1612 KB |
Output is correct |
62 |
Correct |
1 ms |
460 KB |
Output is correct |
63 |
Correct |
1 ms |
460 KB |
Output is correct |
64 |
Correct |
46 ms |
1608 KB |
Output is correct |
65 |
Correct |
51 ms |
1648 KB |
Output is correct |
66 |
Correct |
45 ms |
1612 KB |
Output is correct |
67 |
Correct |
46 ms |
1612 KB |
Output is correct |
68 |
Correct |
47 ms |
1604 KB |
Output is correct |
69 |
Correct |
53 ms |
1720 KB |
Output is correct |
70 |
Correct |
42 ms |
1484 KB |
Output is correct |
71 |
Correct |
48 ms |
1604 KB |
Output is correct |
72 |
Correct |
53 ms |
1648 KB |
Output is correct |