답안 #999317

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
999317 2024-06-15T09:42:58 Z 우민규(#10874) 분수 공원 (IOI21_parks) C++17
5 / 100
467 ms 125760 KB
#include "parks.h"

#include <bits/stdc++.h>
using namespace std;

int construct_roads(vector<int> x, vector<int> y) {
  int n = x.size();
  if (n == 1) {
    build({}, {}, {}, {});
    return 1;
  }
  map<pair<int, int>, int> pts;
  map<pair<int, int>, vector<int>> upd;
  for (int i = 0; i < n; ++i) pts[{y[i], x[i]}] = i;
  int components = n;
  vector<int> par(n);
  iota(par.begin(), par.end(), 0);
  function<int(int)> find = [&](int node) {
    return par[node] == node ? node : par[node] = find(par[node]);
  };
  auto join = [&](int u, int v) {
    u = find(u), v = find(v);
    if (u != v) {
      components -= 1;
      par[u] = v;
    }
  };
  vector<int> u, v, a, b;
  for (auto [k, i] : pts) {
    auto [y, x] = k;
    // construct vertical edge
    if (pts.count({y - 2, x})) {
      int cur = u.size();
      u.push_back(pts[{y - 2, x}]);
      v.push_back(i);
      a.push_back(-1);
      b.push_back(-1);
      join(i, pts[{y - 2, x}]);
      upd[{y - 1, x - 1}].push_back(cur);
      upd[{y - 1, x + 1}].push_back(cur);
    }
    if (pts.count({y, x - 2})) {
      int cur = v.size();
      u.push_back(pts[{y, x - 2}]);
      v.push_back(i);
      a.push_back(-1);
      b.push_back(-1);
      join(i, pts[{y, x - 2}]);
      upd[{y - 1, x - 1}].push_back(cur);
      upd[{y + 1, x - 1}].push_back(cur);
    }
  }
  if (components > 1) {
    return 0;
  }
  function<void(int)> upd_trav;
  // select at point p
  function<void(int, int, int, int, int)> sel_upd = [&](int x, int y, int xp,
                                                        int yp, int v) {
    vector<int> tmp;
    upd[{y, x}].swap(tmp);
    a[v] = x;
    b[v] = y;
    auto it = std::find(upd[{yp, xp}].begin(), upd[{yp, xp}].end(), v);
    if (it != upd[{yp, xp}].end()) upd[{yp, xp}].erase(it);
    for (auto p : tmp)
      if (p != v) upd_trav(p);
    if (!upd[{yp, xp}].empty()) {
      upd[{yp, xp}].swap(tmp);
      for (auto p : tmp) upd_trav(p);
    }
  };
  upd_trav = [&](int p) {
    int cx = (x[u[p]] + x[v[p]]) / 2;
    int cy = (y[u[p]] + y[v[p]]) / 2;
    if (x[u[p]] != x[v[p]]) {
      // {x, y+1}, {x, y-1}
      if (std::find(upd[{cy + 1, cx}].begin(), upd[{cy + 1, cx}].end(), p) !=
          upd[{cy + 1, cx}].end()) {
        sel_upd(cx, cy + 1, cx, cy - 1, p);
      } else {
        sel_upd(cx, cy - 1, cx, cy + 1, p);
      }
    } else {
      if (std::find(upd[{cy, cx - 1}].begin(), upd[{cy, cx - 1}].end(), p) !=
          upd[{cy, cx - 1}].end()) {
        sel_upd(cx - 1, cy, cx + 1, cy, p);
      } else {
        sel_upd(cx + 1, cy, cx - 1, cy, p);
      }
    }
  };
  for (int i = 0; i < u.size(); ++i) {
    if (a[i] == -1 && b[i] == -1) {
      upd_trav(i);
    }
  }
  build(u, v, a, b);
  return 1;
}

#ifndef EVAL
#include "grader.cpp"
#endif

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:93:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |   for (int i = 0; i < u.size(); ++i) {
      |                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 218 ms 36024 KB Output is correct
10 Correct 16 ms 4184 KB Output is correct
11 Correct 93 ms 19404 KB Output is correct
12 Correct 23 ms 5976 KB Output is correct
13 Correct 41 ms 14788 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 204 ms 35928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 218 ms 36024 KB Output is correct
10 Correct 16 ms 4184 KB Output is correct
11 Correct 93 ms 19404 KB Output is correct
12 Correct 23 ms 5976 KB Output is correct
13 Correct 41 ms 14788 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 204 ms 35928 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 467 ms 102912 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 3 ms 860 KB Output is correct
26 Correct 3 ms 1252 KB Output is correct
27 Correct 4 ms 1528 KB Output is correct
28 Correct 171 ms 41400 KB Output is correct
29 Incorrect 270 ms 61864 KB Tree @(3, 80003) appears more than once: for edges on positions 1 and 2
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 218 ms 36024 KB Output is correct
10 Correct 16 ms 4184 KB Output is correct
11 Correct 93 ms 19404 KB Output is correct
12 Correct 23 ms 5976 KB Output is correct
13 Correct 41 ms 14788 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 204 ms 35928 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 467 ms 102912 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 3 ms 860 KB Output is correct
26 Correct 3 ms 1252 KB Output is correct
27 Correct 4 ms 1528 KB Output is correct
28 Correct 171 ms 41400 KB Output is correct
29 Incorrect 270 ms 61864 KB Tree @(3, 80003) appears more than once: for edges on positions 1 and 2
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 218 ms 36024 KB Output is correct
10 Correct 16 ms 4184 KB Output is correct
11 Correct 93 ms 19404 KB Output is correct
12 Correct 23 ms 5976 KB Output is correct
13 Correct 41 ms 14788 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 204 ms 35928 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 432 ms 125760 KB Output is correct
21 Incorrect 426 ms 87976 KB Tree @(5, 9) appears more than once: for edges on positions 9 and 10
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 218 ms 36024 KB Output is correct
10 Correct 16 ms 4184 KB Output is correct
11 Correct 93 ms 19404 KB Output is correct
12 Correct 23 ms 5976 KB Output is correct
13 Correct 41 ms 14788 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 204 ms 35928 KB Output is correct
17 Incorrect 455 ms 72104 KB Tree @(3, 100001) appears more than once: for edges on positions 149998 and 149999
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 218 ms 36024 KB Output is correct
10 Correct 16 ms 4184 KB Output is correct
11 Correct 93 ms 19404 KB Output is correct
12 Correct 23 ms 5976 KB Output is correct
13 Correct 41 ms 14788 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 204 ms 35928 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 467 ms 102912 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 3 ms 860 KB Output is correct
26 Correct 3 ms 1252 KB Output is correct
27 Correct 4 ms 1528 KB Output is correct
28 Correct 171 ms 41400 KB Output is correct
29 Incorrect 270 ms 61864 KB Tree @(3, 80003) appears more than once: for edges on positions 1 and 2
30 Halted 0 ms 0 KB -