답안 #513764

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
513764 2022-01-17T15:08:16 Z chenwz Park (BOI16_park) C++11
100 / 100
871 ms 53328 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define _for(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define _all(i, a, b) for (int i = (a); i <= (int)(b); ++i)

const int VV = 5050;
int T, P, W, H, fa[VV];
LL tx[VV], ty[VV], tr[VV];  // fa[VV];
int find(int x) { return x == fa[x] ? x : (fa[x] = find(fa[x])); }
void merge(int a, int b) { a = find(a), b = find(b), fa[a] = b; }
// Trees T, T + 1, T + 2, T + 3 are the bottom, right, top and left borders.
bool overlap(LL time, LL tree1, LL tree2) {
  if (tree1 >= T) {
    if (tree2 >= T) {
      return false;
    } else {
      if (tree1 == T) return ty[tree2] - tr[tree2] - time < time;
      if (tree1 == T + 1) return tx[tree2] + tr[tree2] + time > W - time;
      if (tree1 == T + 2) return ty[tree2] + tr[tree2] + time > H - time;
      if (tree1 == T + 3) return tx[tree2] - tr[tree2] - time < time;
      throw 5;
      return false;
    }
  } else {
    if (tree2 >= T) {
      return overlap(time, tree2, tree1);
    } else {
      LL dx = tx[tree1] - tx[tree2];
      LL dy = ty[tree1] - ty[tree2];
      LL dist2 = dx * dx + dy * dy;
      LL maxdist2 = tr[tree1] + tr[tree2] + 2 * time;
      maxdist2 *= maxdist2;
      return dist2 < maxdist2;
    }
  }
}

int main() {
  _for(i, 0, VV) fa[i] = i;
  // for (int i = 0; i < VV; ++i)
  cin.sync_with_stdio(false), cin.tie(0);
  cin >> T >> P;
  cin >> W >> H;
  _for(i, 0, T) cin >> tx[i] >> ty[i] >> tr[i];
  // for (LL t = 0; t < T; ++t)

  // ((radius, corner), order)
  vector<pair<pair<LL, LL>, LL>> Q(P);
  for (LL p = 0; p < P; ++p) {
    cin >> Q[p].first.first >> Q[p].first.second;
    --Q[p].first.second;
    Q[p].second = p;
  }
  sort(Q.begin(), Q.end());

  // (time, (tree1, tree2))
  vector<pair<LL, pair<LL, LL>>> events;
  for (LL i = 0; i < T + 4; ++i) {
    for (LL j = i + 1; j < T + 4; ++j) {
      LL A = 0;
      LL B = W + H + 5;
      while (A != B) {
        LL M = (A + B) / 2;
        if (overlap(M, i, j)) {
          B = M;
        } else {
          A = M + 1;
        }
      }
      events.emplace_back(A, make_pair(i, j));
    }
  }
  sort(events.begin(), events.end());

  vector<array<bool, 4>> res(P);
  LL evi = 0;
  for (auto q : Q) {
    while (evi != (LL)events.size() && events[evi].first <= q.first.first) {
      merge(events[evi].second.first, events[evi].second.second);
      ++evi;
    }
    LL c = q.first.second;
    array<bool, 4>& r = res[q.second];
    auto conn = [c](LL a, LL b) {
      return find(T + (c + a) % 4) == find(T + (c + b) % 4);
    };
    r[c] = true;
    if (!conn(0, 1) && !conn(0, 2) && !conn(0, 3)) r[(c + 1) % 4] = true;
    if (!conn(0, 2) && !conn(0, 3) && !conn(1, 2) && !conn(1, 3))
      r[(c + 2) % 4] = true;
    if (!conn(3, 0) && !conn(3, 1) && !conn(3, 2)) r[(c + 3) % 4] = true;
  }
  for (array<bool, 4> r : res) {
    for (LL i = 0; i < 4; ++i) {
      if (r[i]) {
        cout << i + 1;
      }
    }
    cout << '\n';
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 829 ms 49992 KB Output is correct
2 Correct 812 ms 49904 KB Output is correct
3 Correct 835 ms 49784 KB Output is correct
4 Correct 843 ms 49748 KB Output is correct
5 Correct 854 ms 49744 KB Output is correct
6 Correct 857 ms 49856 KB Output is correct
7 Correct 790 ms 49828 KB Output is correct
8 Correct 748 ms 49972 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 5096 KB Output is correct
2 Correct 50 ms 5076 KB Output is correct
3 Correct 49 ms 5044 KB Output is correct
4 Correct 49 ms 5052 KB Output is correct
5 Correct 59 ms 4984 KB Output is correct
6 Correct 50 ms 5132 KB Output is correct
7 Correct 40 ms 4540 KB Output is correct
8 Correct 39 ms 4476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 829 ms 49992 KB Output is correct
2 Correct 812 ms 49904 KB Output is correct
3 Correct 835 ms 49784 KB Output is correct
4 Correct 843 ms 49748 KB Output is correct
5 Correct 854 ms 49744 KB Output is correct
6 Correct 857 ms 49856 KB Output is correct
7 Correct 790 ms 49828 KB Output is correct
8 Correct 748 ms 49972 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 55 ms 5096 KB Output is correct
12 Correct 50 ms 5076 KB Output is correct
13 Correct 49 ms 5044 KB Output is correct
14 Correct 49 ms 5052 KB Output is correct
15 Correct 59 ms 4984 KB Output is correct
16 Correct 50 ms 5132 KB Output is correct
17 Correct 40 ms 4540 KB Output is correct
18 Correct 39 ms 4476 KB Output is correct
19 Correct 871 ms 53116 KB Output is correct
20 Correct 850 ms 53240 KB Output is correct
21 Correct 860 ms 53328 KB Output is correct
22 Correct 867 ms 53240 KB Output is correct
23 Correct 860 ms 53080 KB Output is correct
24 Correct 817 ms 53148 KB Output is correct