답안 #474031

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
474031 2021-09-16T16:51:20 Z idas Park (BOI16_park) C++11
27 / 100
1044 ms 66328 KB
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define SZ(x) ((int)((x).size()))
#define LE(vec) vec[vec.size()-1]
#define TSTS int t; cin >> t; while(t--)solve()

const int INF = 1e9;
const long long LINF = 1e18;
const long double PI = asin(1)*2;
const int MOD = 1e9+7;

using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef long long ll;
typedef long double ld;

void setIO()
{
    FAST_IO;
}

void setIO (string s)
{
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
 	freopen((s+".out").c_str(),"w",stdout);
}

const int N=2e3+10, M=1e5+10;
int n, m, w, h, par[N];
set<int> ans[N];
vector<pair<int, pii>> vis;

int fnd(int u)
{
    return par[u]=par[u]==u?u:fnd(par[u]);
}

bool same(int a, int b)
{
    return fnd(a)==fnd(b);
}

void mrg(int a, int b)
{
    a=fnd(a); b=fnd(b);
    if(a==b) return;
    par[a]=b;
}

void out(int r, int e, int idx)
{
    bool con[5][5];
    FOR(i, 0, 5) FOR(j, 0, 5) con[i][j]=true;
    if(same(n+3, n+1)){
        con[4][1]=false; con[4][2]=false;
        con[3][1]=false; con[3][2]=false;
    }
    if(same(n, n+2)){
        con[1][3]=false; con[1][2]=false;
        con[4][2]=false; con[4][3]=false;
    }

    //1
    if(same(n+3, n+2)){
        con[1][2]=false; con[1][3]=false; con[1][4]=false;
    }
    //2
    if(same(n+1, n+2)){
        con[2][1]=false; con[2][3]=false; con[2][4]=false;
    }
    //3
    if(same(n, n+1)){
        con[3][1]=false; con[3][2]=false; con[3][4]=false;
    }
    //4
    if(same(n, n+3)){
        con[4][1]=false; con[4][2]=false; con[4][3]=false;
    }

    FOR(i, 0, 5)
    {
        FOR(j, 0, 5)
        {
            con[i][j]=(con[i][j]&&con[j][i]);
        }
    }

    FOR(i, 1, 5)
    {
        if(con[e][i]) ans[idx].insert(i);
    }

    /*ans[idx].insert(e);
    if(e==1){
        FOR(i, 1, 5)
        {
            if(con[e][i]) ans[idx].insert(i);
        }
    }
    else if(e==2){
        FOR(i, 1, 5)
        {
            if(con[e][i]) ans[idx].insert(i);
        }
    }
    else if(e==3){
        FOR(i, 1, 5)
        {
            if(con[e][i]) ans[idx].insert(i);
        }
    }
    else{
        FOR(i, 1, 5)
        {
            if(con[e][i]) ans[idx].insert(i);
        }
    }*/
}

int main()
{
    setIO();
    cin >> n >> m >> w >> h;
    vector<pair<int, pii>> in;
    FOR(i, 0, n)
    {
        par[i]=i;
        int x, y, r;
        cin >> x >> y >> r;
        in.PB({r, {x, y}});
    }
    FOR(i, n, n+4) par[i]=i;
    FOR(i, 0, m)
    {
        int r, e;
        cin >> r >> e;
        vis.PB({r, {e, i}});
    }

    sort(vis.begin(), vis.end());

    //up-n
    //right-n+1
    //down-n+2
    //left-n+3
    priority_queue<pair<ld, pii>, vector<pair<ld, pii>>, greater<pair<ld, pii>>> pth;
    FOR(i, 0, (int)in.size())
    {
        FOR(j, i+1, (int)in.size())
        {
            ll x=in[i].S.F, y=in[i].S.S, r=in[i].F, z=in[j].S.F, ww=in[j].S.S, l=in[j].F;
            ll dist=(x-z)*(x-z)+(y-ww)*(y-ww);
            ld b=1;
            ld d=sqrt(b*dist);
            d-=r+l;
            pth.push({d, {i, j}});
        }
        ll x=in[i].S.F, y=in[i].S.S, r=in[i].F;

        pth.push({(h-y-r), {i, n}});
        pth.push({(w-x-r), {i, n+1}});
        pth.push({(y-r), {i, n+2}});
        pth.push({(x-r), {i, n+3}});
    }

    for(auto it : vis){
        int r=it.F, e=it.S.F, idx=it.S.S;
        while(!pth.empty() && pth.top().F<2*r){
            mrg(pth.top().S.F, pth.top().S.S);
            pth.pop();
        }
        out(r, e, idx);
    }

    FOR(i, 0, m)
    {
        for(auto x : ans[i]){
            cout << x;
        }
        cout << '\n';
    }
}

Compilation message

park.cpp: In function 'void setIO(std::string)':
park.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   freopen((s+".in").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:33:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   freopen((s+".out").c_str(),"w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 188 ms 66312 KB Output is correct
2 Correct 184 ms 66240 KB Output is correct
3 Correct 198 ms 66296 KB Output is correct
4 Correct 199 ms 66328 KB Output is correct
5 Correct 186 ms 66204 KB Output is correct
6 Correct 185 ms 66224 KB Output is correct
7 Correct 1044 ms 66264 KB Output is correct
8 Correct 180 ms 66296 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 52 ms 7364 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 188 ms 66312 KB Output is correct
2 Correct 184 ms 66240 KB Output is correct
3 Correct 198 ms 66296 KB Output is correct
4 Correct 199 ms 66328 KB Output is correct
5 Correct 186 ms 66204 KB Output is correct
6 Correct 185 ms 66224 KB Output is correct
7 Correct 1044 ms 66264 KB Output is correct
8 Correct 180 ms 66296 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Runtime error 52 ms 7364 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -