# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1104710 |
2024-10-24T09:10:40 Z |
tuannm |
Park (BOI16_park) |
C++17 |
|
415 ms |
68344 KB |
#include<bits/stdc++.h>
#define ii pair<int, int>
#define ll pair<long long, long long>
#define fi first
#define se second
#define pb push_back
#define eps 1e-10
using namespace std;
const int mod[2] = {1000000007, 998244353};
const int N = 2e3 + 5;
const string NAME = "escaping";
int n, m, w, h;
int p[N], ans[100001];
vector<tuple<int, int, int>> queries;
vector<tuple<long double, int, int>> edges;
int find_set(int u){
if(u == p[u])
return u;
return p[u] = find_set(p[u]);
}
void join_set(int u, int v){
u = find_set(u);
v = find_set(v);
if(u == v)
return;
p[v] = u;
}
struct circ{
int x, y, r;
circ(int _x = 0, int _y = 0, int _r = 0) : x(_x), y(_y), r(_r) {}
} a[N];
long double dis(int i, int j){
long double gg = 1.0 * (a[i].x - a[j].x) * (a[i].x - a[j].x) + 1.0 * (a[i].y - a[j].y) * (a[i].y - a[j].y);
gg = sqrtl(gg);
gg -= 1.0 * (a[i].r + a[j].r);
if(gg < eps)
gg = 0;
return gg;
}
void inp(){
cin >> n >> m >> w >> h;
for(int i = 1; i <= n; ++i){
int x, y, r;
cin >> x >> y >> r;
a[i] = circ(x, y, r);
}
for(int i = 1; i <= m; ++i){
int r, e;
cin >> r >> e;
queries.pb({r, e, i});
}
}
void solve(){
for(int i = 1; i <= n; ++i)
for(int j = i + 1; j <= n; ++j){
long double W = dis(i, j);
edges.pb({W, i, j});
}
for(int i = 1; i <= n; ++i){
long double W = (a[i].x <= a[i].r ? 0 : a[i].x - a[i].r);
edges.pb({W, i, n + 1});
}
for(int i = 1; i <= n; ++i){
long double W = (a[i].y <= a[i].r ? 0 : a[i].y - a[i].r);
edges.pb({W, i, n + 2});
}
for(int i = 1; i <= n; ++i){
long double W = (w - a[i].x <= a[i].r ? 0 : w - a[i].x - a[i].r);
edges.pb({W, i, n + 3});
}
for(int i = 1; i <= n; ++i){
long double W = (h - a[i].y <= a[i].r ? 0 : h - a[i].y - a[i].r);
edges.pb({W, i, n + 4});
}
sort(edges.begin(), edges.end());
sort(queries.begin(), queries.end());
for(int i = 1; i <= n + 4; ++i)
p[i] = i;
int ptr = 0;
for(auto [r, e, i] : queries){
while(ptr < edges.size()){
auto [W, u, v] = edges[ptr];
if(W - 2.0 * r > eps)
break;
++ptr;
join_set(u, v);
}
int g1 = n + e, g2 = n + e % 4 + 1;
g1 = find_set(g1);
g2 = find_set(g2);
if(g1 == g2){
ans[i] |= (1 << e);
continue;
}
for(int j = 1; j <= 4; ++j){
int h1 = n + j, h2 = n + j % 4 + 1;
h1 = find_set(h1);
h2 = find_set(h2);
if(h1 == h2)
continue;
if(g1 != h1 || g1 != h2 || g2 != h1 || g2 != h2)
ans[i] |= (1 << j);
}
}
for(int i = 1; i <= m; ++i){
for(int j = 1; j <= 4; ++j)
if((ans[i] >> j) & 1)
cout << j;
cout << "\n";
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen((NAME + ".inp").c_str(), "r")){
freopen((NAME + ".inp").c_str(), "r", stdin);
freopen((NAME + ".out").c_str(), "w", stdout);
}
inp();
solve();
}
Compilation message
park.cpp: In function 'void solve()':
park.cpp:111:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<long double, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
111 | while(ptr < edges.size()){
| ~~~~^~~~~~~~~~~~~~
park.cpp: In function 'int main()':
park.cpp:157:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
157 | freopen((NAME + ".inp").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:158:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
158 | freopen((NAME + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
398 ms |
68276 KB |
Output is correct |
2 |
Correct |
410 ms |
68272 KB |
Output is correct |
3 |
Correct |
392 ms |
68264 KB |
Output is correct |
4 |
Correct |
408 ms |
68216 KB |
Output is correct |
5 |
Correct |
415 ms |
68268 KB |
Output is correct |
6 |
Correct |
406 ms |
68344 KB |
Output is correct |
7 |
Incorrect |
370 ms |
68240 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
4032 KB |
Output is correct |
2 |
Correct |
35 ms |
3856 KB |
Output is correct |
3 |
Incorrect |
35 ms |
4112 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
398 ms |
68276 KB |
Output is correct |
2 |
Correct |
410 ms |
68272 KB |
Output is correct |
3 |
Correct |
392 ms |
68264 KB |
Output is correct |
4 |
Correct |
408 ms |
68216 KB |
Output is correct |
5 |
Correct |
415 ms |
68268 KB |
Output is correct |
6 |
Correct |
406 ms |
68344 KB |
Output is correct |
7 |
Incorrect |
370 ms |
68240 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |