답안 #237384

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
237384 2020-06-06T10:25:47 Z AM1648 Park (BOI16_park) C++17
100 / 100
375 ms 53496 KB
/* be name khoda */

#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <fstream>
#include <set>
#include <map>
#include <cmath>
using namespace std;

#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

const ll MOD = 1000000007;
const ll INF = 2000000000;
const long long BIG = 1446803456761533460LL;

#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

// -----------------------------------------------------------------------

const ll maxn = 2010;
const ll maxq = 100010;

ll n, m, w, h, en;
ppi tree[maxn];
pii qs[maxq];
pair<double, pii> es[maxn * maxn];
ll dsu[maxn];
bool res[maxq][4];

ll root(ll x) {
    return dsu[x] == x ? x : dsu[x] = root(dsu[x]);
}

double dist(ll a, ll b) {
    if (a == 0) return tree[b].F.F - tree[b].S;
    else if (a == 1) return tree[b].F.S - tree[b].S;
    else if (a == 2) return w - tree[b].F.F - tree[b].S;
    else if (a == 3) return h - tree[b].F.S - tree[b].S;
    else {
        ll x = tree[a].F.F - tree[b].F.F, y = tree[a].F.S - tree[b].F.S;
        return sqrt(x * x + y * y) - tree[a].S - tree[b].S;
    }
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n >> m >> w >> h;
    fori (i, n) cin >> tree[i + 4].F.F >> tree[i + 4].F.S >> tree[i + 4].S;
    fori (i, m) {
        ll r, e; cin >> r >> e; --e;
        qs[i] = {r, e};
        es[en++] = {r * 2, {-1, i}};
    }
    fori (i, n) {
        fori (j, i + 4) {
            es[en++] = {dist(j, i + 4), {j, i + 4}};
        }
    }
    sort(es, es + en);
    iota(dsu, dsu + n + 4, 0);
    fori (i, en) {
        if (es[i].S.F != -1) {
            ll ra = root(es[i].S.F), rb = root(es[i].S.S);
            if (ra != rb) dsu[ra] = rb;
        } else {
            ll qi = es[i].S.S;
            ll ent = qs[qi].S;
            fori (j, 4) res[qi][j] = root(j) != root((j + 1) % 4);
            if (res[qi][ent] == 0) res[qi][0] = res[qi][1] = res[qi][2] = res[qi][3] = 0;
            if (root(0) == root(2)) {
                if (ent < 2) res[qi][2] = res[qi][3] = 0;
                else res[qi][0] = res[qi][1] = 0;
            }
            if (root(1) == root(3)) {
                if (ent == 0 || ent == 3) res[qi][2] = res[qi][1] = 0;
                else res[qi][0] = res[qi][3] = 0;
            }
            res[qi][ent] = 1;
        }
    }
    fori (i, m) {
        fori (j, 4) if (res[i][j]) cout << (char) ('1' + j);
        cout << '\n';
    }

}
# 결과 실행 시간 메모리 Grader output
1 Correct 319 ms 47480 KB Output is correct
2 Correct 323 ms 47480 KB Output is correct
3 Correct 324 ms 47480 KB Output is correct
4 Correct 325 ms 47736 KB Output is correct
5 Correct 319 ms 47736 KB Output is correct
6 Correct 325 ms 47736 KB Output is correct
7 Correct 300 ms 47480 KB Output is correct
8 Correct 294 ms 47608 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 6392 KB Output is correct
2 Correct 55 ms 6520 KB Output is correct
3 Correct 56 ms 6520 KB Output is correct
4 Correct 57 ms 6520 KB Output is correct
5 Correct 56 ms 6648 KB Output is correct
6 Correct 56 ms 6776 KB Output is correct
7 Correct 53 ms 6136 KB Output is correct
8 Correct 56 ms 6136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 319 ms 47480 KB Output is correct
2 Correct 323 ms 47480 KB Output is correct
3 Correct 324 ms 47480 KB Output is correct
4 Correct 325 ms 47736 KB Output is correct
5 Correct 319 ms 47736 KB Output is correct
6 Correct 325 ms 47736 KB Output is correct
7 Correct 300 ms 47480 KB Output is correct
8 Correct 294 ms 47608 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 58 ms 6392 KB Output is correct
12 Correct 55 ms 6520 KB Output is correct
13 Correct 56 ms 6520 KB Output is correct
14 Correct 57 ms 6520 KB Output is correct
15 Correct 56 ms 6648 KB Output is correct
16 Correct 56 ms 6776 KB Output is correct
17 Correct 53 ms 6136 KB Output is correct
18 Correct 56 ms 6136 KB Output is correct
19 Correct 373 ms 53496 KB Output is correct
20 Correct 370 ms 53256 KB Output is correct
21 Correct 365 ms 53368 KB Output is correct
22 Correct 374 ms 53244 KB Output is correct
23 Correct 375 ms 53240 KB Output is correct
24 Correct 351 ms 53368 KB Output is correct