답안 #1094326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1094326 2024-09-29T10:40:22 Z anha3k25cvp Park (BOI16_park) C++14
0 / 100
1246 ms 16824 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;
const dl eps = 1e-6;
 
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 = sqrt(dis(i, j));
	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 ""
    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 <II> g;
    for (int i = 1; i <= n; i ++)
        for (int j = i + 1; j <= n; j ++)
            g.push_back({i, j});
    sort(g.begin(), g.end(), cmp);
    int pos = 0;
    vector <Query> q(m + 1);
    for (int i = 1; i <= m; i ++) {
        cin >>  q[i].r >> q[i].type;
        q[i].id = i;
    }
    sort(q.begin() + 1, q.end());
    Dsu D(n);
    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];
    vector <string> ans(m + 1);
    for (int i = 1; i <= m; i ++) {
        ll r = q[i].r;
        while (pos < g.size() && check(g[pos].st, g[pos].nd, r)) {
            D.unite(g[pos].st, g[pos].nd);
            int u = D.getroot(g[pos].st);
            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];
            pos ++;
        }
        int id = q[i].id, u = q[i].type;
        for (int v = 1; v <= 4; v ++)
            if ((mask & ok[u][v]) == ok[u][v])
                ans[id] += to_string(v);
    }
    for (int i = 1; i <= m; i ++)
        cout << ans[i] << '\n';
    return 0;
}

Compilation message

park.cpp: In function 'int main()':
park.cpp:131:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  131 |         while (pos < g.size() && check(g[pos].st, g[pos].nd, r)) {
      |                ~~~~^~~~~~~~~~
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 );
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1246 ms 16824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 5904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1246 ms 16824 KB Output isn't correct
2 Halted 0 ms 0 KB -