Submission #1094325

# Submission time Handle Problem Language Result Execution time Memory
1094325 2024-09-29T10:38:17 Z anha3k25cvp Park (BOI16_park) C++14
27 / 100
21 ms 632 KB
#include <bits/stdc++.h>
#define ll long long
#define dl long double
#define st first
#define nd second
#define II pair <int, int>

using namespace std;

const int N = 5 + 1e5;
const ll inf = 7 + 4e18;


struct Node {
    ll x, y, r;
};

struct Query {
    ll r;
    int type, id;
    bool operator <(const Query &O) const {
        return r < O.r;
    }
};

struct Rec {
    ll x, y, u, v;
};

vector <Node> e;

struct Dsu {
    int n;
    vector <int> root;
    vector <Rec> R;
    Dsu(int _n = 0) : n(_n) {
        root.assign(n + 1, 0);
        R.resize(n + 1);
        for (int i = 1; i <= n; i ++) {
            root[i] = i;
            R[i].x = e[i].x - e[i].r;
            R[i].y = e[i].y - e[i].r;
            R[i].u = e[i].x + e[i].r;
            R[i].v = e[i].y + e[i].r;
        }
    }
    int getroot(int u) {
        return u == root[u] ? u : root[u] = getroot(root[u]);
    }
    void unite(int u, int v) {
        u = getroot(u); v = getroot(v);
        if (u == v)
            return;
        root[v] = u;
        R[u].x = min(R[u].x, R[v].x);
        R[u].y = min(R[u].y, R[v].y);
        R[u].u = max(R[u].u, R[v].u);
        R[u].v = max(R[u].v, R[v].v);
    }
};

ll spr(ll x) {
    x = abs(x);
    if (x != 0 && x > inf / x)
        return inf;
    return x * x;
}

ll dis(int i, int j) {
    return spr(e[i].x - e[j].x) + spr(e[i].y - e[j].y);
}

dl cal(int i, int j) {
    dl x = spr(e[i].x - e[j].x) + spr(e[i].y - e[j].y) - spr(e[i].r + e[j].r);
    dl y = e[i].r + e[j].r;
    return x / y;
}

bool cmp(II &a, II &b) {
    dl x = cal(a.st, a.nd), y = cal(b.st, b.nd);
    return x < y;
}

int check(int i, int j, ll r) {
    return dis(i, j) < spr(r * 2 + e[i].r + e[j].r);
}

int main() {
#define TASKNAME "code"
    ios_base :: sync_with_stdio (0);
    cin.tie (0);
    if ( fopen( TASKNAME".inp", "r" ) ) {
        freopen( TASKNAME".inp", "r", stdin );
        freopen( TASKNAME".out", "w", stdout );
    }
    int n, m;
    ll w, h;
    cin >> n >> m >> w >> h;
    e.resize(n + 1);
    for (int i = 1; i <= n; i ++)
        cin >> e[i].x >> e[i].y >> e[i].r;
    vector <int> b(6, 63);
    int mask = 63;
    for (int i = 0; i < 6; i ++)
        b[i] -= 1 << i;
    vector <vector <int>> ok(5, vector <int> (5, 0));
    for (int i = 1; i <= 4; i ++)
        ok[i][i] = 0;
    ok[1][2] = 35; ok[1][3] = 53; ok[1][4] = 25;
    ok[2][3] = 22; ok[2][4] = 58;
    ok[3][4] = 44;
    for (int i = 1; i <= 4; i ++)
        for (int j = 1; j < i; j ++)
            ok[i][j] = ok[j][i];
    if (m == 1) {
        ll r, type;
        cin >> r >> type;
        Dsu D(n);
        for (int i = 1; i <= n; i ++)
            for (int j = i + 1; j <= n; j ++)
                if (check(i, j, r))
                    D.unite(i, j);
        int mask = 63;
        for (int u = 1; u <= n; u ++)
            if (u == D.getroot(u)) {
                if (D.R[u].x < r * 2 && D.R[u].y < r * 2)
                    mask &= b[0];
                if (D.R[u].u + r * 2 > w && D.R[u].y < r * 2)
                    mask &= b[1];
                if (D.R[u].u + r * 2 > w && D.R[u].v + r * 2 > h)
                    mask &= b[2];
                if (D.R[u].x < r * 2 && D.R[u].v + r * 2 > h)
                    mask &= b[3];
                if (D.R[u].x < r * 2 && D.R[u].u + r * 2 > w)
                    mask &= b[4];
                if (D.R[u].y < r * 2 && D.R[u].v + r * 2 > h)
                    mask &= b[5];
            }
        for (int i = 1; i <= 4; i ++)
            if ((mask & ok[type][i]) == ok[type][i])
                cout << i;
        return 0;
    }
    return 0;
}

Compilation message

park.cpp: In function 'int main()':
park.cpp:103:9: warning: unused variable 'mask' [-Wunused-variable]
  103 |     int mask = 63;
      |         ^~~~
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".inp", "r", stdin );
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         freopen( TASKNAME".out", "w", stdout );
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 344 KB Output is correct
2 Correct 15 ms 604 KB Output is correct
3 Correct 15 ms 604 KB Output is correct
4 Correct 16 ms 564 KB Output is correct
5 Correct 21 ms 628 KB Output is correct
6 Correct 18 ms 604 KB Output is correct
7 Correct 13 ms 608 KB Output is correct
8 Correct 11 ms 632 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 344 KB Output is correct
2 Correct 15 ms 604 KB Output is correct
3 Correct 15 ms 604 KB Output is correct
4 Correct 16 ms 564 KB Output is correct
5 Correct 21 ms 628 KB Output is correct
6 Correct 18 ms 604 KB Output is correct
7 Correct 13 ms 608 KB Output is correct
8 Correct 11 ms 632 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Incorrect 1 ms 348 KB Output isn't correct
12 Halted 0 ms 0 KB -