# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
670041 |
2022-12-07T21:47:42 Z |
finn__ |
Park (BOI16_park) |
C++17 |
|
373 ms |
56700 KB |
#include <bits/stdc++.h>
using namespace std;
#define sq(x) ((x) * (x))
#define dis(x1, y1, x2, y2, r1, r2) (sqrt(sq(x1 - x2) + sq(y1 - y2)) - r1 - r2)
struct dsu
{
vector<int> z;
dsu(size_t n)
{
z = vector<int>(n, -1);
}
int repr(int u)
{
return z[u] < 0 ? u : (z[u] = repr(z[u]));
}
void unite(int u, int v)
{
u = repr(u);
v = repr(v);
if (u == v)
return;
if (z[u] < z[v])
swap(u, v);
z[v] += z[u];
z[u] = v;
}
bool connected(int u, int v)
{
return repr(u) == repr(v);
}
};
struct tree
{
int64_t x, y, r;
};
struct event
{
size_t i, j;
double t;
bool operator<(event const &e) const
{
return t < e.t;
}
};
struct visitor
{
int64_t r, e;
size_t i;
bool operator<(visitor const &v) const
{
return r < v.r;
}
};
int main()
{
size_t n, m, w, h;
cin >> n >> m >> w >> h;
vector<tree> trees(n);
for (auto &[x, y, r] : trees)
cin >> x >> y >> r;
vector<visitor> visitors(m);
for (size_t i = 0; i < m; i++)
{
cin >> visitors[i].r >> visitors[i].e;
visitors[i].i = i;
}
vector<event> events;
for (size_t i = 0; i < n; i++)
{
auto const &[x1, y1, r1] = trees[i];
for (size_t j = i + 1; j < n; j++)
{
auto const &[x2, y2, r2] = trees[j];
events.push_back({i, j, dis(x1, y1, x2, y2, r1, r2)});
}
events.push_back({i, n, (double)(x1 - r1)});
events.push_back({i, n + 1, (double)(y1 - r1)});
events.push_back({i, n + 2, (double)(w - x1 - r1)});
events.push_back({i, n + 3, (double)(h - y1 - r1)});
}
sort(events.begin(), events.end());
sort(visitors.begin(), visitors.end());
dsu d(n + 4);
auto it = events.begin();
vector<vector<int>> ans(m);
for (auto const [r, e, i] : visitors)
{
while (it != events.end() && it->t + 1e-3 <= 2.0 * (double)r)
{
d.unite(it->i, it->j);
it++;
}
ans[i].push_back(e);
switch (e)
{
case 1:
if (!d.connected(n, n + 1))
{
if (!d.connected(n + 1, n + 3) && !d.connected(n + 1, n + 2))
ans[i].push_back(2);
if (!d.connected(n, n + 2) && !d.connected(n + 1, n + 3) && !d.connected(n + 2, n + 3))
ans[i].push_back(3);
if (!d.connected(n, n + 2) && !d.connected(n, n + 3))
ans[i].push_back(4);
}
break;
case 2:
if (!d.connected(n + 1, n + 2))
{
if (!d.connected(n, n + 2) && !d.connected(n + 2, n + 3))
ans[i].push_back(3);
if (!d.connected(n, n + 2) && !d.connected(n + 1, n + 3) && !d.connected(n, n + 3))
ans[i].push_back(4);
if (!d.connected(n + 1, n + 3) && !d.connected(n, n + 1))
ans[i].push_back(1);
}
break;
case 3:
if (!d.connected(n + 2, n + 3))
{
if (!d.connected(n + 1, n + 3) && !d.connected(n, n + 3))
ans[i].push_back(4);
if (!d.connected(n, n + 2) && !d.connected(n + 1, n + 3) && !d.connected(n, n + 1))
ans[i].push_back(1);
if (!d.connected(n, n + 2) && !d.connected(n + 1, n + 2))
ans[i].push_back(2);
}
break;
case 4:
if (!d.connected(n, n + 3))
{
if (!d.connected(n, n + 2) && !d.connected(n, n + 1))
ans[i].push_back(1);
if (!d.connected(n, n + 2) && !d.connected(n + 1, n + 3) && !d.connected(n + 1, n + 2))
ans[i].push_back(2);
if (!d.connected(n + 1, n + 3) && !d.connected(n + 2, n + 3))
ans[i].push_back(3);
}
break;
}
sort(ans[i].begin(), ans[i].end());
}
for (auto const &v : ans)
{
for (auto const x : v)
cout << x;
cout << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
272 ms |
49756 KB |
Output is correct |
2 |
Correct |
267 ms |
49704 KB |
Output is correct |
3 |
Correct |
273 ms |
49744 KB |
Output is correct |
4 |
Correct |
272 ms |
49700 KB |
Output is correct |
5 |
Correct |
269 ms |
49816 KB |
Output is correct |
6 |
Correct |
271 ms |
49780 KB |
Output is correct |
7 |
Correct |
252 ms |
49768 KB |
Output is correct |
8 |
Correct |
247 ms |
49692 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
9948 KB |
Output is correct |
2 |
Correct |
86 ms |
9928 KB |
Output is correct |
3 |
Correct |
89 ms |
9860 KB |
Output is correct |
4 |
Correct |
85 ms |
9932 KB |
Output is correct |
5 |
Correct |
95 ms |
9940 KB |
Output is correct |
6 |
Correct |
90 ms |
10056 KB |
Output is correct |
7 |
Correct |
82 ms |
9528 KB |
Output is correct |
8 |
Correct |
83 ms |
9536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
272 ms |
49756 KB |
Output is correct |
2 |
Correct |
267 ms |
49704 KB |
Output is correct |
3 |
Correct |
273 ms |
49744 KB |
Output is correct |
4 |
Correct |
272 ms |
49700 KB |
Output is correct |
5 |
Correct |
269 ms |
49816 KB |
Output is correct |
6 |
Correct |
271 ms |
49780 KB |
Output is correct |
7 |
Correct |
252 ms |
49768 KB |
Output is correct |
8 |
Correct |
247 ms |
49692 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
304 KB |
Output is correct |
11 |
Correct |
88 ms |
9948 KB |
Output is correct |
12 |
Correct |
86 ms |
9928 KB |
Output is correct |
13 |
Correct |
89 ms |
9860 KB |
Output is correct |
14 |
Correct |
85 ms |
9932 KB |
Output is correct |
15 |
Correct |
95 ms |
9940 KB |
Output is correct |
16 |
Correct |
90 ms |
10056 KB |
Output is correct |
17 |
Correct |
82 ms |
9528 KB |
Output is correct |
18 |
Correct |
83 ms |
9536 KB |
Output is correct |
19 |
Correct |
361 ms |
56616 KB |
Output is correct |
20 |
Correct |
355 ms |
56596 KB |
Output is correct |
21 |
Correct |
360 ms |
56684 KB |
Output is correct |
22 |
Correct |
347 ms |
56608 KB |
Output is correct |
23 |
Correct |
373 ms |
56576 KB |
Output is correct |
24 |
Correct |
348 ms |
56700 KB |
Output is correct |