Submission #53802

# Submission time Handle Problem Language Result Execution time Memory
53802 2018-07-01T08:30:39 Z ruhanhabib39 Park (BOI16_park) C++17
100 / 100
1215 ms 35724 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2000;
const int MAXM = 1e5;

int n, m;
long long w, h;

struct Tree {
   long long x, y, r;
};

int par[MAXN + 10];
Tree tree[MAXN + 10];

struct Query {
   long long r;
   int e, i;
   bool operator<(Query q) const {
      if(r == q.r) return i < q.i;
      return r < q.r;
   }
};

Query query[MAXM + 10];
bitset<4> res[MAXM + 10];

struct dat {
   long long r; int i, j;
   bool operator<(dat d) const {
      return make_tuple(r, i, j) < make_tuple(d.r, d.i, d.j);
   }
};

long long sq(long long x) {
   return x*x;
}

bool bad(int i, int j, long long r) {
   if(i >= n && j >= n) return false;
   if(j >= n) swap(i, j);
   if(i >= n) {
      switch(i-n) {
      case 0: return tree[j].y - tree[j].r - 2*r < 0LL;
      case 1: return tree[j].x + tree[j].r + 2*r > w;
      case 2: return tree[j].y + tree[j].r + 2*r > h;
      case 3: return tree[j].x - tree[j].r - 2*r < 0LL;
      default: assert(false);
      }
   } else {
      return sq(tree[i].x - tree[j].x) + sq(tree[i].y - tree[j].y) < sq(tree[i].r + tree[j].r + 2*r);
   }
}

int calc(int i, int j) {
   long long lo = 0, hi = w + h + 10;
   while(lo < hi) {
      long long m = (lo + hi) / 2;
      if(bad(i, j, m)) hi = m;
      else lo = m+1;
   }
   return lo;
}

int find(int i) {
   if(par[i] == -1) return i;
   return par[i] = find(par[i]);
}

void merge(int i, int j) {
   i = find(i); j = find(j);
   if(i == j) return;
   par[i] = j;
}

void work() {
   vector<dat> vec;
   for(int i = 0; i < n+4; i++) {
      for(int j = i+1; j < n+4; j++) {
         vec.push_back(dat{calc(i, j), i, j});
      }
   }
   sort(vec.begin(), vec.end());

   memset(par, -1, sizeof par);
   int vi = -1;
   for(int qi = 0; qi < m; qi++) {
      auto qq = query[qi];
      while(vi+1 < (int)vec.size() && vec[vi+1].r <= qq.r) {
         vi++;
         merge(vec[vi].i, vec[vi].j);
      }

      auto good = [qq](int i, int j) {
         return find(n + (qq.e + i) % 4) != find(n + (qq.e + j) % 4);
      };
      
      res[qq.i][qq.e] = true;
      if(good(0, 3) && good(0, 2) && good(0, 1)) res[qq.i][(qq.e + 1) % 4] = true;
      if(good(0, 3) && good(0, 2) && good(1, 2) && good(1, 3)) res[qq.i][(qq.e + 2) % 4] = true;
      if(good(3, 0) && good(3, 2) && good(3, 1)) res[qq.i][(qq.e + 3) % 4] = true;
   }
}

int main() {
   scanf("%d%d%lld%lld", &n, &m, &w, &h);
   for(int i = 0; i < n; i++) {
      scanf("%lld%lld%lld", &tree[i].x, &tree[i].y, &tree[i].r);
   }
   for(int i = 0; i < m; i++) {
      scanf("%lld%d", &query[i].r, &query[i].e);
      query[i].e--;
      query[i].i = i;
   }
   sort(query, query + m);

   work();
   for(int i = 0; i < m; i++) {
      for(int e = 0; e < 4; e++) {
         if(res[i][e]) printf("%d", e+1);
      }
      printf("\n");
   }
}

Compilation message

park.cpp: In function 'int main()':
park.cpp:107:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d%d%lld%lld", &n, &m, &w, &h);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:109:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%lld%lld%lld", &tree[i].x, &tree[i].y, &tree[i].r);
       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:112:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%lld%d", &query[i].r, &query[i].e);
       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1152 ms 33468 KB Output is correct
2 Correct 1142 ms 33608 KB Output is correct
3 Correct 1090 ms 33760 KB Output is correct
4 Correct 1144 ms 33932 KB Output is correct
5 Correct 1085 ms 33932 KB Output is correct
6 Correct 1088 ms 34016 KB Output is correct
7 Correct 1004 ms 34016 KB Output is correct
8 Correct 1018 ms 34188 KB Output is correct
9 Correct 2 ms 34188 KB Output is correct
10 Correct 2 ms 34188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 34188 KB Output is correct
2 Correct 74 ms 34188 KB Output is correct
3 Correct 79 ms 34188 KB Output is correct
4 Correct 77 ms 34188 KB Output is correct
5 Correct 75 ms 34188 KB Output is correct
6 Correct 99 ms 34188 KB Output is correct
7 Correct 65 ms 34188 KB Output is correct
8 Correct 62 ms 34188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1152 ms 33468 KB Output is correct
2 Correct 1142 ms 33608 KB Output is correct
3 Correct 1090 ms 33760 KB Output is correct
4 Correct 1144 ms 33932 KB Output is correct
5 Correct 1085 ms 33932 KB Output is correct
6 Correct 1088 ms 34016 KB Output is correct
7 Correct 1004 ms 34016 KB Output is correct
8 Correct 1018 ms 34188 KB Output is correct
9 Correct 2 ms 34188 KB Output is correct
10 Correct 2 ms 34188 KB Output is correct
11 Correct 85 ms 34188 KB Output is correct
12 Correct 74 ms 34188 KB Output is correct
13 Correct 79 ms 34188 KB Output is correct
14 Correct 77 ms 34188 KB Output is correct
15 Correct 75 ms 34188 KB Output is correct
16 Correct 99 ms 34188 KB Output is correct
17 Correct 65 ms 34188 KB Output is correct
18 Correct 62 ms 34188 KB Output is correct
19 Correct 1167 ms 35620 KB Output is correct
20 Correct 1181 ms 35700 KB Output is correct
21 Correct 1215 ms 35700 KB Output is correct
22 Correct 1108 ms 35700 KB Output is correct
23 Correct 1117 ms 35700 KB Output is correct
24 Correct 1064 ms 35724 KB Output is correct