# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
132018 |
2019-07-18T08:06:29 Z |
이온조(#3189) |
Fences (JOI18_fences) |
C++14 |
|
1000 ms |
47340 KB |
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using pid = pair<int, double>;
using pdi = pair<double, int>;
using pdd = pair<double, double>;
#define X first
#define Y second
const double eps = 1e-6;
struct line { pdd S, E; };
struct dot { pdd D; int id; bool ps; };
struct node { double v; int c, id; };
bool operator <(node PP, node QQ) { return PP.v > QQ.v; }
inline double f(double x) { return max(x, -x); }
inline double dst(pdd A, pdd B) { return sqrt((A.X-B.X) * (A.X-B.X) + (A.Y-B.Y) * (A.Y-B.Y)); }
inline double CCW(pdd A, pdd B, pdd C) { return A.X*B.Y + B.X*C.Y + C.X*A.Y - A.Y*B.X - B.Y*C.X - C.Y*A.X; }
inline int CCWs(pdd A, pdd B, pdd C) {
int tmp = CCW(A, B, C);
if(tmp < 0) return -1;
if(tmp > 0) return +1;
if(tmp == 0) return 0;
}
inline bool on(line A, pdd B) {
if(A.S > A.E) swap(A.S, A.E);
if(B < A.S || A.E < B) return false;
return f(CCW(A.S, A.E, B)) < eps;
}
inline bool its(line A, line B) { // strict
if(on(A, B.S) || on(A, B.E) || on(B, A.S) || on(B, A.E)) return false;
return CCWs(A.S, A.E, B.S) * CCWs(A.S, A.E, B.E) == -1 && CCWs(B.S, B.E, A.S) * CCWs(B.S, B.E, A.E) == -1;
}
inline pdd push(line A, pdd B) {
double ds = dst(A.S, A.E);
double d = f(CCW(A.S, A.E, B) / ds);
double dx = A.S.Y - A.E.Y, dy = A.E.X - A.S.X;
pdd PA = {B.X + dx * (d/ds), B.Y + dy * (d/ds)};
pdd PB = {B.X - dx * (d/ds), B.Y - dy * (d/ds)};
if(dst(PA, A.S) > dst(PB, A.S)) swap(PA, PB);
return PA;
}
line I = {{0.0, 0.0}, {1000.0, 1.0}};
vector<dot> T;
vector<pid> adj[1000009];
line A[111];
int N, S, K;
double ans = 1e9, D[2][1000009];
inline bool ok(line L) {
bool f = 0;
f |= its(L, {{S, S}, {-S, -S}});
f |= its(L, {{-S, S}, {S, -S}});
return !f;
}
void dijk(int st) {
// printf("start: (%d, %d)\n", T[st].D.X, T[st].D.Y);
vector<pii> rec = {{0, st}};
D[0][st] = 0.0;
priority_queue<node> pq; pq.push({0.0, 0, st});
while(pq.size()) {
node n = pq.top(); pq.pop();
if((n.id == st && n.c == 1) || n.v > ans) break;
// printf("now: (%f, %d, (%d, %d))\n", n.v, n.c, T[n.id].D.X, T[n.id].D.Y);
if(f(D[n.c][n.id] - n.v) > eps) continue;
for(auto& it: adj[n.id]) {
int tc = n.c;
if(its({T[n.id].D, T[it.X].D}, I)) tc = 1 - tc;
if(D[tc][it.X] > n.v + it.Y) {
D[tc][it.X] = n.v + it.Y;
rec.push_back({tc, it.X});
pq.push({D[tc][it.X], tc, it.X});
}
}
}
ans = min(ans, D[1][st]);
for(auto& it: rec) D[it.X][it.Y] = 1e9;
}
void make_edge(int u, int v, double c) {
adj[u].push_back({v, c});
adj[v].push_back({u, c});
}
int main() {
scanf("%d%d",&N,&S);
// N = 100; S = 100;
ans = 8.0*S;
for(int i=1; i<=N; i++) {
scanf("%lf%lf%lf%lf", &A[i].S.X, &A[i].S.Y, &A[i].E.X, &A[i].E.Y);
// A[i].S = {i, 100}; A[i].E = {i+1, 100};
T.push_back({A[i].S, i, 0});
T.push_back({A[i].E, i, 0});
}
T.push_back({{S, S}, N+1, 0});
T.push_back({{S, -S}, N+2, 0});
T.push_back({{-S, -S}, N+3, 0});
T.push_back({{-S, S}, N+4, 0});
int L = T.size();
for(int i=1; i<=N; i++) {
for(int j=0; j<T.size(); j++) {
if(i == T[j].id) continue;
pdd pu = push(A[i], T[j].D);
bool f = (ok({T[j].D, pu}) && on(A[i], pu));
for(int k=1; k<=N && f; k++) f &= !its({pu, T[j].D}, A[k]);
if(f) {
// puts("ok");
int u = T.size();
T.push_back({pu, i, 1});
make_edge(u, j, dst(pu, T[j].D));
make_edge(u, 2*i-2, 0);
}
// else puts("not ok");
}
}
K = T.size();
// printf("K: %d\n", K);
// for(auto& it: T) {
// printf("position(%f, %f), id: %d, pushed?: %d\n", it.D.X, it.D.Y, it.id, it.ps);
// }
for(int i=0; i<L; i++) {
for(int j=i+1; j<L; j++) {
if(!ok({T[i].D, T[j].D})) continue;
bool f = 1;
for(int k=1; k<=N && f; k++) f &= !its({T[i].D, T[j].D}, A[k]);
if(!f) continue;
double d;
if(T[i].id == T[j].id) d = 0;
else d = dst(T[i].D, T[j].D);
// printf("(%f, %f) <----> (%f, %f), cost: %f\n", T[i].D.X, T[i].D.Y, T[j].D.X, T[j].D.Y, d);
adj[i].push_back({j, d});
adj[j].push_back({i, d});
}
}
for(int i=0; i<K; i++) D[0][i] = D[1][i] = 1e9;
for(int i=0; i<2*N; i+=2) dijk(i);
for(int i=2*N; i<2*N+4; i++) dijk(i);
printf("%.10f", ans);
return 0;
}
Compilation message
fences.cpp: In function 'int main()':
fences.cpp:108:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0; j<T.size(); j++) {
~^~~~~~~~~
fences.cpp: In function 'int CCWs(pdd, pdd, pdd)':
fences.cpp:27:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
fences.cpp: In function 'int main()':
fences.cpp:91:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&N,&S);
~~~~~^~~~~~~~~~~~~~
fences.cpp:95:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lf%lf%lf%lf", &A[i].S.X, &A[i].S.Y, &A[i].E.X, &A[i].E.Y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
23928 KB |
Output is correct |
2 |
Correct |
25 ms |
23800 KB |
Output is correct |
3 |
Correct |
25 ms |
23800 KB |
Output is correct |
4 |
Correct |
25 ms |
23800 KB |
Output is correct |
5 |
Correct |
26 ms |
23800 KB |
Output is correct |
6 |
Correct |
25 ms |
23800 KB |
Output is correct |
7 |
Correct |
25 ms |
23804 KB |
Output is correct |
8 |
Correct |
25 ms |
23800 KB |
Output is correct |
9 |
Correct |
25 ms |
23800 KB |
Output is correct |
10 |
Correct |
26 ms |
23828 KB |
Output is correct |
11 |
Correct |
25 ms |
23800 KB |
Output is correct |
12 |
Correct |
28 ms |
23848 KB |
Output is correct |
13 |
Correct |
25 ms |
23776 KB |
Output is correct |
14 |
Correct |
30 ms |
23804 KB |
Output is correct |
15 |
Correct |
28 ms |
23928 KB |
Output is correct |
16 |
Correct |
26 ms |
23928 KB |
Output is correct |
17 |
Correct |
25 ms |
23736 KB |
Output is correct |
18 |
Correct |
25 ms |
23800 KB |
Output is correct |
19 |
Correct |
25 ms |
23800 KB |
Output is correct |
20 |
Correct |
25 ms |
23800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
23928 KB |
Output is correct |
2 |
Correct |
25 ms |
23800 KB |
Output is correct |
3 |
Correct |
25 ms |
23800 KB |
Output is correct |
4 |
Correct |
25 ms |
23800 KB |
Output is correct |
5 |
Correct |
26 ms |
23800 KB |
Output is correct |
6 |
Correct |
25 ms |
23800 KB |
Output is correct |
7 |
Correct |
25 ms |
23804 KB |
Output is correct |
8 |
Correct |
25 ms |
23800 KB |
Output is correct |
9 |
Correct |
25 ms |
23800 KB |
Output is correct |
10 |
Correct |
26 ms |
23828 KB |
Output is correct |
11 |
Correct |
25 ms |
23800 KB |
Output is correct |
12 |
Correct |
28 ms |
23848 KB |
Output is correct |
13 |
Correct |
25 ms |
23776 KB |
Output is correct |
14 |
Correct |
30 ms |
23804 KB |
Output is correct |
15 |
Correct |
28 ms |
23928 KB |
Output is correct |
16 |
Correct |
26 ms |
23928 KB |
Output is correct |
17 |
Correct |
25 ms |
23736 KB |
Output is correct |
18 |
Correct |
25 ms |
23800 KB |
Output is correct |
19 |
Correct |
25 ms |
23800 KB |
Output is correct |
20 |
Correct |
25 ms |
23800 KB |
Output is correct |
21 |
Correct |
25 ms |
23800 KB |
Output is correct |
22 |
Correct |
26 ms |
23800 KB |
Output is correct |
23 |
Correct |
26 ms |
23928 KB |
Output is correct |
24 |
Correct |
25 ms |
23748 KB |
Output is correct |
25 |
Correct |
24 ms |
23800 KB |
Output is correct |
26 |
Correct |
25 ms |
23804 KB |
Output is correct |
27 |
Correct |
26 ms |
23800 KB |
Output is correct |
28 |
Correct |
26 ms |
23772 KB |
Output is correct |
29 |
Correct |
26 ms |
23784 KB |
Output is correct |
30 |
Correct |
25 ms |
23804 KB |
Output is correct |
31 |
Correct |
25 ms |
23804 KB |
Output is correct |
32 |
Correct |
25 ms |
23928 KB |
Output is correct |
33 |
Correct |
25 ms |
23800 KB |
Output is correct |
34 |
Correct |
25 ms |
23800 KB |
Output is correct |
35 |
Correct |
25 ms |
23800 KB |
Output is correct |
36 |
Correct |
27 ms |
23800 KB |
Output is correct |
37 |
Correct |
25 ms |
23800 KB |
Output is correct |
38 |
Correct |
25 ms |
23800 KB |
Output is correct |
39 |
Correct |
26 ms |
23800 KB |
Output is correct |
40 |
Correct |
25 ms |
23800 KB |
Output is correct |
41 |
Correct |
23 ms |
23800 KB |
Output is correct |
42 |
Correct |
26 ms |
23800 KB |
Output is correct |
43 |
Correct |
25 ms |
23800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
23928 KB |
Output is correct |
2 |
Correct |
25 ms |
23800 KB |
Output is correct |
3 |
Correct |
25 ms |
23800 KB |
Output is correct |
4 |
Correct |
25 ms |
23800 KB |
Output is correct |
5 |
Correct |
26 ms |
23800 KB |
Output is correct |
6 |
Correct |
25 ms |
23800 KB |
Output is correct |
7 |
Correct |
25 ms |
23804 KB |
Output is correct |
8 |
Correct |
25 ms |
23800 KB |
Output is correct |
9 |
Correct |
25 ms |
23800 KB |
Output is correct |
10 |
Correct |
26 ms |
23828 KB |
Output is correct |
11 |
Correct |
25 ms |
23800 KB |
Output is correct |
12 |
Correct |
28 ms |
23848 KB |
Output is correct |
13 |
Correct |
25 ms |
23776 KB |
Output is correct |
14 |
Correct |
30 ms |
23804 KB |
Output is correct |
15 |
Correct |
28 ms |
23928 KB |
Output is correct |
16 |
Correct |
26 ms |
23928 KB |
Output is correct |
17 |
Correct |
25 ms |
23736 KB |
Output is correct |
18 |
Correct |
25 ms |
23800 KB |
Output is correct |
19 |
Correct |
25 ms |
23800 KB |
Output is correct |
20 |
Correct |
25 ms |
23800 KB |
Output is correct |
21 |
Correct |
25 ms |
23800 KB |
Output is correct |
22 |
Correct |
26 ms |
23800 KB |
Output is correct |
23 |
Correct |
26 ms |
23928 KB |
Output is correct |
24 |
Correct |
25 ms |
23748 KB |
Output is correct |
25 |
Correct |
24 ms |
23800 KB |
Output is correct |
26 |
Correct |
25 ms |
23804 KB |
Output is correct |
27 |
Correct |
26 ms |
23800 KB |
Output is correct |
28 |
Correct |
26 ms |
23772 KB |
Output is correct |
29 |
Correct |
26 ms |
23784 KB |
Output is correct |
30 |
Correct |
25 ms |
23804 KB |
Output is correct |
31 |
Correct |
25 ms |
23804 KB |
Output is correct |
32 |
Correct |
25 ms |
23928 KB |
Output is correct |
33 |
Correct |
25 ms |
23800 KB |
Output is correct |
34 |
Correct |
25 ms |
23800 KB |
Output is correct |
35 |
Correct |
25 ms |
23800 KB |
Output is correct |
36 |
Correct |
27 ms |
23800 KB |
Output is correct |
37 |
Correct |
25 ms |
23800 KB |
Output is correct |
38 |
Correct |
25 ms |
23800 KB |
Output is correct |
39 |
Correct |
26 ms |
23800 KB |
Output is correct |
40 |
Correct |
25 ms |
23800 KB |
Output is correct |
41 |
Correct |
23 ms |
23800 KB |
Output is correct |
42 |
Correct |
26 ms |
23800 KB |
Output is correct |
43 |
Correct |
25 ms |
23800 KB |
Output is correct |
44 |
Correct |
86 ms |
24236 KB |
Output is correct |
45 |
Correct |
134 ms |
24300 KB |
Output is correct |
46 |
Correct |
177 ms |
24472 KB |
Output is correct |
47 |
Correct |
150 ms |
24288 KB |
Output is correct |
48 |
Correct |
89 ms |
24184 KB |
Output is correct |
49 |
Correct |
136 ms |
24388 KB |
Output is correct |
50 |
Correct |
152 ms |
24240 KB |
Output is correct |
51 |
Correct |
140 ms |
24188 KB |
Output is correct |
52 |
Correct |
148 ms |
24264 KB |
Output is correct |
53 |
Correct |
123 ms |
24348 KB |
Output is correct |
54 |
Correct |
111 ms |
24216 KB |
Output is correct |
55 |
Correct |
136 ms |
24308 KB |
Output is correct |
56 |
Correct |
148 ms |
24240 KB |
Output is correct |
57 |
Correct |
153 ms |
24232 KB |
Output is correct |
58 |
Correct |
170 ms |
24280 KB |
Output is correct |
59 |
Correct |
140 ms |
24220 KB |
Output is correct |
60 |
Correct |
152 ms |
24272 KB |
Output is correct |
61 |
Correct |
133 ms |
24268 KB |
Output is correct |
62 |
Correct |
26 ms |
23800 KB |
Output is correct |
63 |
Correct |
26 ms |
23800 KB |
Output is correct |
64 |
Correct |
142 ms |
24420 KB |
Output is correct |
65 |
Correct |
224 ms |
24680 KB |
Output is correct |
66 |
Correct |
179 ms |
24668 KB |
Output is correct |
67 |
Execution timed out |
1040 ms |
47340 KB |
Time limit exceeded |
68 |
Halted |
0 ms |
0 KB |
- |