# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1075068 |
2024-08-25T18:02:56 Z |
Mighilon |
Park (BOI16_park) |
C++17 |
|
314 ms |
57284 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "../Library/debug.h"
#else
#define dbg(x...)
#endif
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; --i)
#define trav(a, x) for (auto& a : x)
#define f first
#define s second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
const char nl = '\n';
const int INF = 1e9;
const int MOD = 1e9 + 7;
struct DSU {
vector<int> par, sz;
int c; // connected components
DSU(int n) : par(n), c(n) {
sz.resize(n, 1);
for (int i = 0; i < n; ++i) par[i] = i;
}
int find(int i) {
return par[i] == i ? i : (par[i] = find(par[i]));
}
bool same(int i, int j) {
return find(i) == find(j);
}
int get_size(int i) {
return sz[find(i)];
}
int count() {
return c;
}
int merge(int i, int j) {
if ((i = find(i)) == (j = find(j))) return -1;
else --c;
if (sz[i] > sz[j]) swap(i, j);
par[i] = j;
sz[j] += sz[i];
return j;
}
};
struct Point{
int x, y, r;
};
void solve(){
int n, q;
cin >> n >> q;
int w, h;
cin >> w >> h;
vector<Point> a(n);
vector<array<ll, 3>> e;
auto distance = [&](ll x1, ll y1, ll x2, ll y2, ll r1, ll r2){
return (ll)sqrt(abs(x1 - x2) * abs(x1 - x2) + abs(y1 - y2) * abs(y1 - y2)) - r1 - r2;
};
F0R(i, n){
cin >> a[i].x >> a[i].y >> a[i].r;
e.push_back({distance(a[i].x, a[i].y, a[i].x, 0, a[i].r, 0), i + 4, 0});
e.push_back({distance(a[i].x, a[i].y, w, a[i].y, a[i].r, 0), i + 4, 1});
e.push_back({distance(a[i].x, a[i].y, a[i].x, h, a[i].r, 0), i + 4, 2});
e.push_back({distance(a[i].x, a[i].y, 0, a[i].y, a[i].r, 0), i + 4, 3});
}
F0R(i, n)
FOR(j, i + 1, n)
e.push_back({distance(a[i].x, a[i].y, a[j].x, a[j].y, a[i].r, a[j].r), i + 4, j + 4});
vpi que(q);
vi id(q); F0R(i, q) id[i] = i;
F0R(i, q){
cin >> que[i].f >> que[i].s;
que[i].f <<= 1;
}
sort(all(id), [&](int i, int j){return que[i].f < que[j].f;});
sort(all(e));
DSU dsu(n + 4);
int j = 0;
vector<vector<bool>> ans(q);
F0R(i, q){
while(j < sz(e) && e[j][0] < que[id[i]].f){
dsu.merge(e[j][1], e[j][2]);
j++;
}
dbg(que[id[i]])
dbg(j)
auto calculate = [&](int a, int b, int c, int d) -> vector<bool>{
vector<bool> ans(4, false);
if(dsu.same(a, d))
return ans;
if(!dsu.same(a, b) && !dsu.same(a, c))
ans[b] = true;
if(!dsu.same(b, c) && !dsu.same(a, c) && !dsu.same(d, b))
ans[c] = true;
if(!dsu.same(d, b) && !dsu.same(d, c))
ans[d] = true;
return ans;
};
if(que[id[i]].s == 1)
ans[id[i]] = calculate(0, 1, 2, 3), ans[id[i]][que[id[i]].s - 1] = true;
else if(que[id[i]].s == 2)
ans[id[i]] = calculate(1, 2, 3, 0), ans[id[i]][que[id[i]].s - 1] = true;
else if(que[id[i]].s == 3)
ans[id[i]] = calculate(2, 3, 0, 1), ans[id[i]][que[id[i]].s - 1] = true;
else if(que[id[i]].s == 4)
ans[id[i]] = calculate(3, 0, 1, 2), ans[id[i]][que[id[i]].s - 1] = true;
}
F0R(i, q){
F0R(j, 4){
if(ans[i][j])
cout << j + 1;
}
cout << nl;
}
dbg(id)
}
int32_t main(){
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int TC = 1;
// cin >> TC;
while(TC--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
261 ms |
49844 KB |
Output is correct |
2 |
Correct |
270 ms |
49844 KB |
Output is correct |
3 |
Correct |
272 ms |
49816 KB |
Output is correct |
4 |
Correct |
257 ms |
49792 KB |
Output is correct |
5 |
Correct |
269 ms |
49888 KB |
Output is correct |
6 |
Correct |
262 ms |
49840 KB |
Output is correct |
7 |
Correct |
249 ms |
49820 KB |
Output is correct |
8 |
Correct |
246 ms |
49896 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
10372 KB |
Output is correct |
2 |
Correct |
50 ms |
10568 KB |
Output is correct |
3 |
Correct |
45 ms |
10440 KB |
Output is correct |
4 |
Correct |
47 ms |
10500 KB |
Output is correct |
5 |
Correct |
43 ms |
10700 KB |
Output is correct |
6 |
Correct |
43 ms |
10500 KB |
Output is correct |
7 |
Correct |
40 ms |
10064 KB |
Output is correct |
8 |
Correct |
39 ms |
10064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
261 ms |
49844 KB |
Output is correct |
2 |
Correct |
270 ms |
49844 KB |
Output is correct |
3 |
Correct |
272 ms |
49816 KB |
Output is correct |
4 |
Correct |
257 ms |
49792 KB |
Output is correct |
5 |
Correct |
269 ms |
49888 KB |
Output is correct |
6 |
Correct |
262 ms |
49840 KB |
Output is correct |
7 |
Correct |
249 ms |
49820 KB |
Output is correct |
8 |
Correct |
246 ms |
49896 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
41 ms |
10372 KB |
Output is correct |
12 |
Correct |
50 ms |
10568 KB |
Output is correct |
13 |
Correct |
45 ms |
10440 KB |
Output is correct |
14 |
Correct |
47 ms |
10500 KB |
Output is correct |
15 |
Correct |
43 ms |
10700 KB |
Output is correct |
16 |
Correct |
43 ms |
10500 KB |
Output is correct |
17 |
Correct |
40 ms |
10064 KB |
Output is correct |
18 |
Correct |
39 ms |
10064 KB |
Output is correct |
19 |
Correct |
303 ms |
57104 KB |
Output is correct |
20 |
Correct |
314 ms |
57172 KB |
Output is correct |
21 |
Correct |
310 ms |
57284 KB |
Output is correct |
22 |
Correct |
298 ms |
57148 KB |
Output is correct |
23 |
Correct |
314 ms |
57004 KB |
Output is correct |
24 |
Correct |
303 ms |
57172 KB |
Output is correct |