답안 #1023276

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1023276 2024-07-14T14:44:27 Z NeroZein 분수 공원 (IOI21_parks) C++17
55 / 100
1657 ms 212148 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std; 

const int N = 2e5 + 5;

int p[N];
int sz[N];
set<int> se[N];
set<int> to_cross[N];
set<pair<int, int>> from_cross[N];

int get(int v) {
  return p[v] = (p[v] == v ? v : get(p[v]));
}

void unite(int u, int v) {
  u = get(u);
  v = get(v);
  if (sz[u] > sz[v]) swap(u, v);
  p[u] = v;
  sz[v] += sz[u];
}

int construct_roads(vector<int> vx, vector<int> vy) {
  int n = (int) vx.size();
  map<pair<int, int>, int> mp;
  for (int i = 0; i < n; ++i) {
    p[i] = i;
    sz[i] = 1;
    mp[{vx[i], vy[i]}] = i;
  }
  for (int i = 0; i < n; ++i) {
    int x = vx[i], y = vy[i];
    for (int dx : {-2, 0, 2}) {
      for (int dy : {-2, 0, 2}) {
        if (dx != 0 && dy != 0) continue; 
        if (mp.count({x + dx, y + dy})) {
          int id = mp[{x + dx, y + dy}];
          if (get(id) != get(i)) {
            unite(i, id);
            se[i].insert(id);
            se[id].insert(i);
          }
        } 
      }
    }
  }
  if (sz[get(1)] != n) {
    return 0; 
  }
  vector<int> u, v, a, b;
  for (int i = 0; i < n; ++i) {
    bool ok = true; 
    int x = vx[i], y = vy[i];
    for (int dx : {-2, 0, 2}) {
      for (int dy : {-2, 0, 2}) {
        if (dx != 0 && dy != 0) continue; 
        ok &= mp.count({x + dx, y + dy});
      }
    }
    if (ok) {
      for (int dx : {-2, 2}) {
        int id = mp[{x + dx, y}];
        u.push_back(i);
        v.push_back(id);
        a.push_back(x + dx / 2);
        b.push_back(y + (dx < 0 ? -1 : 1));
        se[id].erase(i);
        se[i].erase(id);
      }
      for (int dy : {-2, 2}) {
        int id = mp[{x, y + dy}];
        u.push_back(i);
        v.push_back(id); 
        a.push_back(x + (dy < 0 ? 1 : -1));
        b.push_back(y + dy / 2);
        se[id].erase(i);
        se[i].erase(id);
      }
    }
  }
  int cnt = 0; 
  vector<int> type;
  vector<set<int>> g;
  map<pair<int, int>, int> crosses;
  map<int, pair<int, int>> lines, bck;
  for (int i = 0; i < n; ++i) {
    int x = vx[i], y = vy[i];
    for (int id : se[i]) {
      if (id < i) continue;
      int xx = vx[id], yy = vy[id];
      int line_id = cnt;
      type.push_back(0);//type[cnt]
      g.push_back({});
      lines[cnt++] = {i, id};
      for (int d : {-1, 1}) {
        int cx, cy;
        if (x == xx) {
          cx = x + d, cy = (y + yy) / 2; 
        } else {
          cx = (x + xx) / 2, cy = y + d;
        }
        if (!crosses.count({cx, cy})) {
          g.push_back({});
          type.push_back(1);
          bck[cnt] = {cx, cy};
          crosses[{cx, cy}] = cnt++;
        }
        int cross_id = crosses[{cx, cy}];
        g[cross_id].insert(line_id);
        g[line_id].insert(cross_id);
      }
    }
  }
  queue<int> que;
  vector<int> indeg(cnt);
  for (int i = 0; i < cnt; ++i) {
    indeg[i] = g[i].size();
    if (g[i].size() == 1) {
      assert(type[i] == 1);
      que.push(i);
    }
  }
  set<int> mentioned;
  while (!que.empty()) {
    int cur = que.front();
    que.pop();
    if (indeg[cur] == 0) {
      continue; 
    }
    if (type[cur] == 0) {
      for (int w : g[cur]) {
        g[w].erase(cur);
        --indeg[w];
        if (indeg[w] == 1) {
          que.push(w);
        }
      }
    } else {
      int line_id = *g[cur].begin();
      if (!mentioned.count(line_id)) {
        mentioned.insert(line_id); 
        u.push_back(lines[line_id].first);
        v.push_back(lines[line_id].second);
        a.push_back(bck[cur].first);
        b.push_back(bck[cur].second);        
      }
      for (int w : g[cur]) {
        g[w].erase(cur);
        --indeg[w];
        if (indeg[w] == 1) {
          que.push(w); 
        }
      }
    }
  }
  build(u, v, a, b);
  return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 29276 KB Output is correct
2 Correct 7 ms 29276 KB Output is correct
3 Correct 8 ms 29276 KB Output is correct
4 Correct 9 ms 29276 KB Output is correct
5 Correct 8 ms 29164 KB Output is correct
6 Correct 7 ms 29276 KB Output is correct
7 Correct 7 ms 29276 KB Output is correct
8 Correct 8 ms 29276 KB Output is correct
9 Correct 625 ms 118984 KB Output is correct
10 Correct 40 ms 38180 KB Output is correct
11 Correct 238 ms 77644 KB Output is correct
12 Correct 61 ms 42784 KB Output is correct
13 Correct 44 ms 36848 KB Output is correct
14 Correct 9 ms 29272 KB Output is correct
15 Correct 14 ms 29644 KB Output is correct
16 Correct 650 ms 118828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 29276 KB Output is correct
2 Correct 7 ms 29276 KB Output is correct
3 Correct 8 ms 29276 KB Output is correct
4 Correct 9 ms 29276 KB Output is correct
5 Correct 8 ms 29164 KB Output is correct
6 Correct 7 ms 29276 KB Output is correct
7 Correct 7 ms 29276 KB Output is correct
8 Correct 8 ms 29276 KB Output is correct
9 Correct 625 ms 118984 KB Output is correct
10 Correct 40 ms 38180 KB Output is correct
11 Correct 238 ms 77644 KB Output is correct
12 Correct 61 ms 42784 KB Output is correct
13 Correct 44 ms 36848 KB Output is correct
14 Correct 9 ms 29272 KB Output is correct
15 Correct 14 ms 29644 KB Output is correct
16 Correct 650 ms 118828 KB Output is correct
17 Correct 9 ms 29272 KB Output is correct
18 Correct 8 ms 29276 KB Output is correct
19 Correct 8 ms 29180 KB Output is correct
20 Correct 7 ms 29276 KB Output is correct
21 Correct 8 ms 29276 KB Output is correct
22 Correct 8 ms 29276 KB Output is correct
23 Correct 1444 ms 179336 KB Output is correct
24 Correct 10 ms 29272 KB Output is correct
25 Correct 13 ms 30092 KB Output is correct
26 Correct 13 ms 29788 KB Output is correct
27 Correct 12 ms 29888 KB Output is correct
28 Correct 473 ms 89244 KB Output is correct
29 Correct 783 ms 124884 KB Output is correct
30 Correct 1101 ms 151084 KB Output is correct
31 Correct 1462 ms 179240 KB Output is correct
32 Correct 7 ms 29272 KB Output is correct
33 Correct 10 ms 29276 KB Output is correct
34 Correct 7 ms 29276 KB Output is correct
35 Correct 8 ms 29272 KB Output is correct
36 Correct 7 ms 29276 KB Output is correct
37 Correct 8 ms 29108 KB Output is correct
38 Correct 7 ms 29276 KB Output is correct
39 Correct 10 ms 29276 KB Output is correct
40 Correct 8 ms 29276 KB Output is correct
41 Correct 8 ms 29276 KB Output is correct
42 Correct 9 ms 29276 KB Output is correct
43 Correct 10 ms 29532 KB Output is correct
44 Correct 11 ms 29788 KB Output is correct
45 Correct 630 ms 107644 KB Output is correct
46 Correct 1022 ms 144784 KB Output is correct
47 Correct 1000 ms 144892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 29276 KB Output is correct
2 Correct 7 ms 29276 KB Output is correct
3 Correct 8 ms 29276 KB Output is correct
4 Correct 9 ms 29276 KB Output is correct
5 Correct 8 ms 29164 KB Output is correct
6 Correct 7 ms 29276 KB Output is correct
7 Correct 7 ms 29276 KB Output is correct
8 Correct 8 ms 29276 KB Output is correct
9 Correct 625 ms 118984 KB Output is correct
10 Correct 40 ms 38180 KB Output is correct
11 Correct 238 ms 77644 KB Output is correct
12 Correct 61 ms 42784 KB Output is correct
13 Correct 44 ms 36848 KB Output is correct
14 Correct 9 ms 29272 KB Output is correct
15 Correct 14 ms 29644 KB Output is correct
16 Correct 650 ms 118828 KB Output is correct
17 Correct 9 ms 29272 KB Output is correct
18 Correct 8 ms 29276 KB Output is correct
19 Correct 8 ms 29180 KB Output is correct
20 Correct 7 ms 29276 KB Output is correct
21 Correct 8 ms 29276 KB Output is correct
22 Correct 8 ms 29276 KB Output is correct
23 Correct 1444 ms 179336 KB Output is correct
24 Correct 10 ms 29272 KB Output is correct
25 Correct 13 ms 30092 KB Output is correct
26 Correct 13 ms 29788 KB Output is correct
27 Correct 12 ms 29888 KB Output is correct
28 Correct 473 ms 89244 KB Output is correct
29 Correct 783 ms 124884 KB Output is correct
30 Correct 1101 ms 151084 KB Output is correct
31 Correct 1462 ms 179240 KB Output is correct
32 Correct 7 ms 29272 KB Output is correct
33 Correct 10 ms 29276 KB Output is correct
34 Correct 7 ms 29276 KB Output is correct
35 Correct 8 ms 29272 KB Output is correct
36 Correct 7 ms 29276 KB Output is correct
37 Correct 8 ms 29108 KB Output is correct
38 Correct 7 ms 29276 KB Output is correct
39 Correct 10 ms 29276 KB Output is correct
40 Correct 8 ms 29276 KB Output is correct
41 Correct 8 ms 29276 KB Output is correct
42 Correct 9 ms 29276 KB Output is correct
43 Correct 10 ms 29532 KB Output is correct
44 Correct 11 ms 29788 KB Output is correct
45 Correct 630 ms 107644 KB Output is correct
46 Correct 1022 ms 144784 KB Output is correct
47 Correct 1000 ms 144892 KB Output is correct
48 Correct 8 ms 29272 KB Output is correct
49 Correct 8 ms 29188 KB Output is correct
50 Correct 8 ms 29220 KB Output is correct
51 Incorrect 8 ms 29208 KB Tree @(5, 5) appears more than once: for edges on positions 1 and 4
52 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 29276 KB Output is correct
2 Correct 7 ms 29276 KB Output is correct
3 Correct 8 ms 29276 KB Output is correct
4 Correct 9 ms 29276 KB Output is correct
5 Correct 8 ms 29164 KB Output is correct
6 Correct 7 ms 29276 KB Output is correct
7 Correct 7 ms 29276 KB Output is correct
8 Correct 8 ms 29276 KB Output is correct
9 Correct 625 ms 118984 KB Output is correct
10 Correct 40 ms 38180 KB Output is correct
11 Correct 238 ms 77644 KB Output is correct
12 Correct 61 ms 42784 KB Output is correct
13 Correct 44 ms 36848 KB Output is correct
14 Correct 9 ms 29272 KB Output is correct
15 Correct 14 ms 29644 KB Output is correct
16 Correct 650 ms 118828 KB Output is correct
17 Correct 8 ms 29276 KB Output is correct
18 Correct 8 ms 29192 KB Output is correct
19 Correct 7 ms 29212 KB Output is correct
20 Correct 1485 ms 173360 KB Output is correct
21 Correct 1556 ms 173252 KB Output is correct
22 Correct 1523 ms 173340 KB Output is correct
23 Correct 1140 ms 182624 KB Output is correct
24 Correct 319 ms 45656 KB Output is correct
25 Correct 456 ms 64340 KB Output is correct
26 Correct 442 ms 64336 KB Output is correct
27 Correct 1404 ms 210160 KB Output is correct
28 Correct 1361 ms 210372 KB Output is correct
29 Correct 1454 ms 210324 KB Output is correct
30 Correct 1479 ms 210324 KB Output is correct
31 Correct 8 ms 29272 KB Output is correct
32 Correct 67 ms 39432 KB Output is correct
33 Correct 130 ms 38796 KB Output is correct
34 Correct 1539 ms 175692 KB Output is correct
35 Correct 21 ms 31060 KB Output is correct
36 Correct 122 ms 38484 KB Output is correct
37 Correct 202 ms 47980 KB Output is correct
38 Correct 492 ms 83116 KB Output is correct
39 Correct 752 ms 103388 KB Output is correct
40 Correct 1110 ms 128484 KB Output is correct
41 Correct 1371 ms 145700 KB Output is correct
42 Correct 1657 ms 166004 KB Output is correct
43 Correct 9 ms 29276 KB Output is correct
44 Correct 9 ms 29276 KB Output is correct
45 Correct 9 ms 29276 KB Output is correct
46 Correct 9 ms 29276 KB Output is correct
47 Correct 9 ms 29276 KB Output is correct
48 Correct 8 ms 29272 KB Output is correct
49 Correct 9 ms 29272 KB Output is correct
50 Correct 9 ms 29276 KB Output is correct
51 Correct 12 ms 29108 KB Output is correct
52 Correct 9 ms 29272 KB Output is correct
53 Correct 9 ms 29276 KB Output is correct
54 Correct 11 ms 29532 KB Output is correct
55 Correct 11 ms 29684 KB Output is correct
56 Correct 693 ms 108520 KB Output is correct
57 Correct 1055 ms 146052 KB Output is correct
58 Correct 1091 ms 146124 KB Output is correct
59 Correct 11 ms 29272 KB Output is correct
60 Correct 9 ms 29276 KB Output is correct
61 Correct 10 ms 29276 KB Output is correct
62 Correct 1504 ms 212148 KB Output is correct
63 Correct 1461 ms 212120 KB Output is correct
64 Correct 1432 ms 211352 KB Output is correct
65 Correct 14 ms 30036 KB Output is correct
66 Correct 18 ms 30552 KB Output is correct
67 Correct 663 ms 103640 KB Output is correct
68 Correct 1162 ms 143560 KB Output is correct
69 Correct 1656 ms 180740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 29276 KB Output is correct
2 Correct 7 ms 29276 KB Output is correct
3 Correct 8 ms 29276 KB Output is correct
4 Correct 9 ms 29276 KB Output is correct
5 Correct 8 ms 29164 KB Output is correct
6 Correct 7 ms 29276 KB Output is correct
7 Correct 7 ms 29276 KB Output is correct
8 Correct 8 ms 29276 KB Output is correct
9 Correct 625 ms 118984 KB Output is correct
10 Correct 40 ms 38180 KB Output is correct
11 Correct 238 ms 77644 KB Output is correct
12 Correct 61 ms 42784 KB Output is correct
13 Correct 44 ms 36848 KB Output is correct
14 Correct 9 ms 29272 KB Output is correct
15 Correct 14 ms 29644 KB Output is correct
16 Correct 650 ms 118828 KB Output is correct
17 Correct 1600 ms 210532 KB Output is correct
18 Correct 1570 ms 210420 KB Output is correct
19 Correct 1636 ms 175708 KB Output is correct
20 Correct 853 ms 77968 KB Output is correct
21 Correct 1121 ms 136436 KB Output is correct
22 Correct 9 ms 29276 KB Output is correct
23 Correct 164 ms 51640 KB Output is correct
24 Correct 41 ms 33016 KB Output is correct
25 Correct 144 ms 42436 KB Output is correct
26 Correct 269 ms 51796 KB Output is correct
27 Correct 636 ms 93312 KB Output is correct
28 Correct 849 ms 108320 KB Output is correct
29 Correct 1055 ms 129588 KB Output is correct
30 Correct 1282 ms 142088 KB Output is correct
31 Correct 1555 ms 158316 KB Output is correct
32 Correct 1470 ms 190316 KB Output is correct
33 Correct 1455 ms 211988 KB Output is correct
34 Correct 14 ms 30040 KB Output is correct
35 Correct 22 ms 30808 KB Output is correct
36 Correct 668 ms 103648 KB Output is correct
37 Correct 1105 ms 143188 KB Output is correct
38 Correct 1578 ms 181196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 29276 KB Output is correct
2 Correct 7 ms 29276 KB Output is correct
3 Correct 8 ms 29276 KB Output is correct
4 Correct 9 ms 29276 KB Output is correct
5 Correct 8 ms 29164 KB Output is correct
6 Correct 7 ms 29276 KB Output is correct
7 Correct 7 ms 29276 KB Output is correct
8 Correct 8 ms 29276 KB Output is correct
9 Correct 625 ms 118984 KB Output is correct
10 Correct 40 ms 38180 KB Output is correct
11 Correct 238 ms 77644 KB Output is correct
12 Correct 61 ms 42784 KB Output is correct
13 Correct 44 ms 36848 KB Output is correct
14 Correct 9 ms 29272 KB Output is correct
15 Correct 14 ms 29644 KB Output is correct
16 Correct 650 ms 118828 KB Output is correct
17 Correct 9 ms 29272 KB Output is correct
18 Correct 8 ms 29276 KB Output is correct
19 Correct 8 ms 29180 KB Output is correct
20 Correct 7 ms 29276 KB Output is correct
21 Correct 8 ms 29276 KB Output is correct
22 Correct 8 ms 29276 KB Output is correct
23 Correct 1444 ms 179336 KB Output is correct
24 Correct 10 ms 29272 KB Output is correct
25 Correct 13 ms 30092 KB Output is correct
26 Correct 13 ms 29788 KB Output is correct
27 Correct 12 ms 29888 KB Output is correct
28 Correct 473 ms 89244 KB Output is correct
29 Correct 783 ms 124884 KB Output is correct
30 Correct 1101 ms 151084 KB Output is correct
31 Correct 1462 ms 179240 KB Output is correct
32 Correct 7 ms 29272 KB Output is correct
33 Correct 10 ms 29276 KB Output is correct
34 Correct 7 ms 29276 KB Output is correct
35 Correct 8 ms 29272 KB Output is correct
36 Correct 7 ms 29276 KB Output is correct
37 Correct 8 ms 29108 KB Output is correct
38 Correct 7 ms 29276 KB Output is correct
39 Correct 10 ms 29276 KB Output is correct
40 Correct 8 ms 29276 KB Output is correct
41 Correct 8 ms 29276 KB Output is correct
42 Correct 9 ms 29276 KB Output is correct
43 Correct 10 ms 29532 KB Output is correct
44 Correct 11 ms 29788 KB Output is correct
45 Correct 630 ms 107644 KB Output is correct
46 Correct 1022 ms 144784 KB Output is correct
47 Correct 1000 ms 144892 KB Output is correct
48 Correct 8 ms 29272 KB Output is correct
49 Correct 8 ms 29188 KB Output is correct
50 Correct 8 ms 29220 KB Output is correct
51 Incorrect 8 ms 29208 KB Tree @(5, 5) appears more than once: for edges on positions 1 and 4
52 Halted 0 ms 0 KB -