Submission #474041

# Submission time Handle Problem Language Result Execution time Memory
474041 2021-09-16T17:11:28 Z idas Park (BOI16_park) C++11
0 / 100
540 ms 25368 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=5e3+10, M=5e5+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);
    }
}

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());

    priority_queue<pair<float, pii>, vector<pair<float, pii>>, greater<pair<float, 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);
            float d=sqrt(dist);
            d-=ld(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<(float)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);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 126 ms 25300 KB Output is correct
2 Correct 131 ms 25292 KB Output is correct
3 Correct 127 ms 25308 KB Output is correct
4 Correct 127 ms 25252 KB Output is correct
5 Correct 125 ms 25368 KB Output is correct
6 Correct 126 ms 25292 KB Output is correct
7 Correct 540 ms 25348 KB Output is correct
8 Correct 117 ms 25248 KB Output is correct
9 Incorrect 1 ms 460 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 39 ms 4548 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 126 ms 25300 KB Output is correct
2 Correct 131 ms 25292 KB Output is correct
3 Correct 127 ms 25308 KB Output is correct
4 Correct 127 ms 25252 KB Output is correct
5 Correct 125 ms 25368 KB Output is correct
6 Correct 126 ms 25292 KB Output is correct
7 Correct 540 ms 25348 KB Output is correct
8 Correct 117 ms 25248 KB Output is correct
9 Incorrect 1 ms 460 KB Output isn't correct
10 Halted 0 ms 0 KB -