Submission #658965

# Submission time Handle Problem Language Result Execution time Memory
658965 2022-11-15T16:13:13 Z victor_gao Park (BOI16_park) C++17
100 / 100
386 ms 56352 KB
//#pragma GCC optimize("Ofast,unroll-loops,O3")
//#pragma GCC optimize("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native")
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//#pragma pack(1)
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define N 2015
#define eps 1e-6
using namespace std;
//using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> order_multiset;
//typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> order_set;
struct dsu{
    int boss[N],sz[N];
    void init(int n){
        for (int i=0;i<=n+5;i++){
            boss[i]=i; sz[i]=1;
        }
    }
    int find(int x){
        if (boss[x]==x) return x;
        return boss[x]=find(boss[x]);
    }
    void Merge(int a,int b){
        int ra=find(a),rb=find(b);
        if (ra==rb) return;
        if (sz[ra]<sz[rb]) swap(ra,rb);
        boss[rb]=ra;
        sz[ra]+=sz[rb];
    }
}d;
/*
左側 n+1, 右側 n+2, 上面 n+3, 下面 n+4
5 3
16 11
11 8 1
6 10 1
7 3 2
10 4 1
15 5 1
1 1
2 2
2 1
*/
int n,m,w,h,r[N],vis[6];
string ans[100015];
vector<int>g[6];
vector<pair<double,pii> >edge;
vector<pair<int,pii> >people;
pii pos[N];
double count(int i,int j){
    return sqrt(1.0*(pos[i].x-pos[j].x)*(pos[i].x-pos[j].x)+1.0*(pos[i].y-pos[j].y)*(pos[i].y-pos[j].y))-r[i]-r[j];
}
void dfs(int p){
    if (vis[p]) return;
    vis[p]=1;
    for (auto i:g[p])
        dfs(i);
}
void add_edge(int i,int j){
    g[i].push_back(j);
    g[j].push_back(i);
}
string count_ans(int start){
    for (int i=0;i<5;i++){
        vis[i]=0;
        g[i].clear();
    }
    int L=d.find(n+1),R=d.find(n+2);
    int U=d.find(n+3),D=d.find(n+4);
    if (L!=U&&L!=D&&L!=R) add_edge(1,4);
    if (R!=L&&R!=U&&R!=D) add_edge(2,3);
    if (D!=L&&D!=U&&D!=R) add_edge(1,2);
    if (U!=L&&U!=R&&U!=D) add_edge(3,4);
    if (U!=D&&L!=R){
        if (U!=L&&D!=R) add_edge(2,4);
        if (L!=D&&U!=R) add_edge(1,3);
    }
    dfs(start);
    string tans="";
    for (int i=0;i<5;i++){
        if (vis[i]) tans=tans+(char)(i+'0');
    }
    return tans;
}
signed main(){
    fast
    cin>>n>>m>>w>>h;
    for (int i=1;i<=n;i++)
        cin>>pos[i].x>>pos[i].y>>r[i];
    d.init(n+4);
    for (int i=1;i<=m;i++){
        int r,e; cin>>r>>e;
        people.push_back({r,{e,i}});
    }
    for (int i=1;i<=n;i++){
        for (int j=i+1;j<=n;j++){
            double dis=count(i,j);
            edge.push_back({dis,{i,j}});
        }
    }
    for (int i=1;i<=n;i++){
        edge.push_back({h-pos[i].y-r[i],{i,n+3}});
        edge.push_back({pos[i].x-r[i],{i,n+1}});
        edge.push_back({pos[i].y-r[i],{i,n+4}});
        edge.push_back({w-pos[i].x-r[i],{i,n+2}});
    }
    sort(people.begin(),people.end());
    sort(edge.begin(),edge.end());
    int p=0;
    for (auto i:edge){
        while (p<m&&i.x-2*people[p].x>=-eps){
            int st=people[p].y.x;
            ans[people[p].y.y]=count_ans(st);
            p++;
        }
        d.Merge(i.y.x,i.y.y);
    }
    for (int i=1;i<=m;i++)
        cout<<ans[i]<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 324 ms 52888 KB Output is correct
2 Correct 315 ms 52876 KB Output is correct
3 Correct 324 ms 52852 KB Output is correct
4 Correct 321 ms 52916 KB Output is correct
5 Correct 335 ms 52924 KB Output is correct
6 Correct 313 ms 52884 KB Output is correct
7 Correct 312 ms 52864 KB Output is correct
8 Correct 294 ms 52904 KB Output is correct
9 Correct 2 ms 3412 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 7352 KB Output is correct
2 Correct 48 ms 7348 KB Output is correct
3 Correct 52 ms 7356 KB Output is correct
4 Correct 48 ms 7360 KB Output is correct
5 Correct 52 ms 7324 KB Output is correct
6 Correct 59 ms 7468 KB Output is correct
7 Correct 45 ms 6652 KB Output is correct
8 Correct 50 ms 7616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 324 ms 52888 KB Output is correct
2 Correct 315 ms 52876 KB Output is correct
3 Correct 324 ms 52852 KB Output is correct
4 Correct 321 ms 52916 KB Output is correct
5 Correct 335 ms 52924 KB Output is correct
6 Correct 313 ms 52884 KB Output is correct
7 Correct 312 ms 52864 KB Output is correct
8 Correct 294 ms 52904 KB Output is correct
9 Correct 2 ms 3412 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
11 Correct 60 ms 7352 KB Output is correct
12 Correct 48 ms 7348 KB Output is correct
13 Correct 52 ms 7356 KB Output is correct
14 Correct 48 ms 7360 KB Output is correct
15 Correct 52 ms 7324 KB Output is correct
16 Correct 59 ms 7468 KB Output is correct
17 Correct 45 ms 6652 KB Output is correct
18 Correct 50 ms 7616 KB Output is correct
19 Correct 368 ms 56224 KB Output is correct
20 Correct 366 ms 56352 KB Output is correct
21 Correct 357 ms 56208 KB Output is correct
22 Correct 386 ms 56196 KB Output is correct
23 Correct 356 ms 56204 KB Output is correct
24 Correct 367 ms 56348 KB Output is correct