답안 #1101533

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101533 2024-10-16T09:33:05 Z Requiem Park (BOI16_park) C++17
0 / 100
508 ms 95060 KB
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define inf 1e18
#define fi first
#define se second
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define endl '\n'
#define pi 3.14159265359
#define TASKNAME "escaping"
using namespace std;
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
const int MAXN = 4009;
const int MAXM = 4000009;
int n,m;
int w, h;

struct circle{
    int x, y, r;
    circle(int _x = 0, int _y = 0, int _r = 0): x(_x), y(_y), r(_r) {}
} C[MAXN];

ii query[MAXM];

/**
Giả sử ta coi bốn đỉnh là góc là 4 đỉnh của đồ thị.
bài này sẽ tư duy theo hướng criteria + visualization.
**/

pair<double, ii> edge[MAXM];

struct DSU{
    vector<int> lab;
    DSU(int sz = 0){
        lab.resize(sz + 9, -1);
    }

    int root(int u){
        return (lab[u] < 0) ? u : lab[u] = root(lab[u]);
    }

    bool unite(int u, int v){
        u = root(u);
        v = root(v);
        if (u != v){
            if (lab[u] > lab[v]) swap(u, v);
            lab[u] += lab[v];
            lab[v] = u;
            return true;
        }
        return false;
    }
};

enum{
    down, right, up, left
};
double distance(int i, int j){
    return 1.0 * sqrt((C[i].x - C[j].x) * (C[i].x - C[j].x) + (C[i].y - C[j].y) * (C[i].y - C[j].y)) - (C[i].r + C[j].r);
}

vector<int> g[MAXN];

double minR[5][5];

void dfs(int u, int p, double res, int origin){

    if (u > n){
        minR[origin][u - n - 1] = res;
    }


    for(auto id: g[u]){
        int v = edge[id].se.fi + edge[id].se.se - u;
        double w = edge[id].fi;
        if (v == p) continue;
        dfs(v, u, max(res, w), origin);
    }
}
main()
{
    fast;
    if (fopen(TASKNAME".inp","r")){
        freopen(TASKNAME".inp","r",stdin);
        freopen(TASKNAME".out","w",stdout);
    }
    cin >> n >> m;
    cin >> w >> h;
    FOR(i, 1, n){
        cin >> C[i].x >> C[i].y >> C[i].r;
    }

    FOR(i, 1, m){
        cin >> query[i].fi >> query[i].se;
        query[i].se--;
    }


    int cntEdge = 0;
    FOR(i, 1, n){
        FOR(j, 1, n){
            edge[++cntEdge] = {distance(i, j), ii(i, j)};
        }
        edge[++cntEdge] = {C[i].y - 0, ii(n + 1, i)};
        edge[++cntEdge] = {h - C[i].y, ii(n + 3, i)};
        edge[++cntEdge] = {C[i].x - 0, ii(n + 4, i)};
        edge[++cntEdge] = {w - C[i].x, ii(n + 2, i)};
    }

    sort(edge + 1, edge + 1 + cntEdge);


    DSU D(n + 5);
    FOR(i, 1, cntEdge){
        int u = edge[i].se.fi;
        int v = edge[i].se.se;
        if (D.unite(u, v)){
            g[u].pb(i);
            g[v].pb(i);
//            cout << u << ' ' << v << ' ' << edge[i].fi << endl;
        }
    }
    dfs(n + 1, -1, -inf, 0);
    dfs(n + 2, -1, -inf, 1);
    dfs(n + 3, -1, -inf, 2);
    dfs(n + 4, -1, -inf, 3);
//    FOR(i, 0, 3){
//        FOR(j, 0, 3){
//            cout << minR[i][j] << ' ';
//        }
//        cout << endl;
//    }
//    cout << endl;

    FOR(i, 1, m){
        int r = query[i].fi * 2;
        int c = query[i].se;
//        cout << r << ' ' << c << endl;

        vector<int> goable;
        goable.pb(c);

        bool check = true;
        if (minR[c][(c + 1) % 4] <= r or minR[c][(c + 2)%4] <= r or minR[c][(c + 3) % 4] <= r) check = false;
        if (check) goable.pb((c + 1) % 4);

        check = true;
        if (minR[c][(c + 2) % 4] <= r or minR[(c + 1) % 4][(c + 3) % 4] <= r or minR[(c + 1) % 4][(c + 2)%4] <= r
            or minR[(c + 3)%4][c] <= r) check = false;

        if (check) goable.pb((c + 2) % 4);

        check = true;
        if (minR[c][(c + 3) % 4] <= r or minR[(c + 1) % 4][(c + 3) % 4] <= r
            or minR[(c + 2) % 4][(c + 3) % 4] <= r) check = false;

        if (check) goable.pb((c + 3) % 4);

        sort(goable.begin(), goable.end());
        FOR(i, 0, (int) goable.size() - 1){
            cout << goable[i] + 1;
        }
        cout <<endl;
    }
}
/**
Warning:
Cận lmao
Code imple thiếu case nào không.
Limit.
**/

Compilation message

park.cpp:88:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   88 | main()
      | ^~~~
park.cpp: In function 'int main()':
park.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(TASKNAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(TASKNAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 508 ms 95060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 34 ms 8268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 508 ms 95060 KB Output isn't correct
2 Halted 0 ms 0 KB -