Submission #1023273

# Submission time Handle Problem Language Result Execution time Memory
1023273 2024-07-14T14:42:56 Z NeroZein Fountain Parks (IOI21_parks) C++17
15 / 100
1775 ms 212660 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) {
      cout << i << endl; 
      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] == 1) {
      //cout << "cross: " << bck[cur].first << ' ' << bck[cur].second << endl; 
    //} else {
      //int i = lines[cur].first, j = lines[cur].second;
      //cout << "line: " << vx[i] << ' ' << vy[i] << ' ' << vx[j] << ' ' << vy[j] << endl; 
    //}
    //assert(indeg[cur] == (int) g[cur].size() && g[cur].size() == 1);
    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;
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 28508 KB Output is correct
2 Correct 11 ms 28508 KB Output is correct
3 Correct 11 ms 28508 KB Output is correct
4 Correct 13 ms 28508 KB Output is correct
5 Correct 12 ms 28504 KB Output is correct
6 Correct 12 ms 28504 KB Output is correct
7 Correct 18 ms 28508 KB Output is correct
8 Correct 12 ms 28504 KB Output is correct
9 Correct 689 ms 119488 KB Output is correct
10 Correct 50 ms 37636 KB Output is correct
11 Correct 296 ms 77516 KB Output is correct
12 Correct 77 ms 42160 KB Output is correct
13 Correct 54 ms 36720 KB Output is correct
14 Correct 15 ms 28764 KB Output is correct
15 Correct 19 ms 28848 KB Output is correct
16 Correct 729 ms 119500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 28508 KB Output is correct
2 Correct 11 ms 28508 KB Output is correct
3 Correct 11 ms 28508 KB Output is correct
4 Correct 13 ms 28508 KB Output is correct
5 Correct 12 ms 28504 KB Output is correct
6 Correct 12 ms 28504 KB Output is correct
7 Correct 18 ms 28508 KB Output is correct
8 Correct 12 ms 28504 KB Output is correct
9 Correct 689 ms 119488 KB Output is correct
10 Correct 50 ms 37636 KB Output is correct
11 Correct 296 ms 77516 KB Output is correct
12 Correct 77 ms 42160 KB Output is correct
13 Correct 54 ms 36720 KB Output is correct
14 Correct 15 ms 28764 KB Output is correct
15 Correct 19 ms 28848 KB Output is correct
16 Correct 729 ms 119500 KB Output is correct
17 Correct 16 ms 28508 KB Output is correct
18 Correct 14 ms 28508 KB Output is correct
19 Correct 16 ms 28508 KB Output is correct
20 Correct 14 ms 28508 KB Output is correct
21 Correct 14 ms 28508 KB Output is correct
22 Correct 19 ms 28552 KB Output is correct
23 Correct 1775 ms 180952 KB Output is correct
24 Correct 13 ms 28384 KB Output is correct
25 Correct 16 ms 29532 KB Output is correct
26 Correct 17 ms 29192 KB Output is correct
27 Correct 18 ms 29276 KB Output is correct
28 Correct 512 ms 89520 KB Output is correct
29 Correct 861 ms 125668 KB Output is correct
30 Correct 1218 ms 152264 KB Output is correct
31 Correct 1581 ms 180940 KB Output is correct
32 Correct 13 ms 28504 KB Output is correct
33 Correct 14 ms 28508 KB Output is correct
34 Correct 13 ms 28508 KB Output is correct
35 Correct 14 ms 28624 KB Output is correct
36 Correct 13 ms 28508 KB Output is correct
37 Correct 13 ms 28508 KB Output is correct
38 Correct 13 ms 28504 KB Output is correct
39 Correct 13 ms 28400 KB Output is correct
40 Correct 12 ms 28508 KB Output is correct
41 Correct 14 ms 28508 KB Output is correct
42 Correct 12 ms 28508 KB Output is correct
43 Correct 15 ms 28764 KB Output is correct
44 Correct 17 ms 29020 KB Output is correct
45 Correct 702 ms 108776 KB Output is correct
46 Correct 1105 ms 146120 KB Output is correct
47 Correct 1144 ms 146140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 28508 KB Output is correct
2 Correct 11 ms 28508 KB Output is correct
3 Correct 11 ms 28508 KB Output is correct
4 Correct 13 ms 28508 KB Output is correct
5 Correct 12 ms 28504 KB Output is correct
6 Correct 12 ms 28504 KB Output is correct
7 Correct 18 ms 28508 KB Output is correct
8 Correct 12 ms 28504 KB Output is correct
9 Correct 689 ms 119488 KB Output is correct
10 Correct 50 ms 37636 KB Output is correct
11 Correct 296 ms 77516 KB Output is correct
12 Correct 77 ms 42160 KB Output is correct
13 Correct 54 ms 36720 KB Output is correct
14 Correct 15 ms 28764 KB Output is correct
15 Correct 19 ms 28848 KB Output is correct
16 Correct 729 ms 119500 KB Output is correct
17 Correct 16 ms 28508 KB Output is correct
18 Correct 14 ms 28508 KB Output is correct
19 Correct 16 ms 28508 KB Output is correct
20 Correct 14 ms 28508 KB Output is correct
21 Correct 14 ms 28508 KB Output is correct
22 Correct 19 ms 28552 KB Output is correct
23 Correct 1775 ms 180952 KB Output is correct
24 Correct 13 ms 28384 KB Output is correct
25 Correct 16 ms 29532 KB Output is correct
26 Correct 17 ms 29192 KB Output is correct
27 Correct 18 ms 29276 KB Output is correct
28 Correct 512 ms 89520 KB Output is correct
29 Correct 861 ms 125668 KB Output is correct
30 Correct 1218 ms 152264 KB Output is correct
31 Correct 1581 ms 180940 KB Output is correct
32 Correct 13 ms 28504 KB Output is correct
33 Correct 14 ms 28508 KB Output is correct
34 Correct 13 ms 28508 KB Output is correct
35 Correct 14 ms 28624 KB Output is correct
36 Correct 13 ms 28508 KB Output is correct
37 Correct 13 ms 28508 KB Output is correct
38 Correct 13 ms 28504 KB Output is correct
39 Correct 13 ms 28400 KB Output is correct
40 Correct 12 ms 28508 KB Output is correct
41 Correct 14 ms 28508 KB Output is correct
42 Correct 12 ms 28508 KB Output is correct
43 Correct 15 ms 28764 KB Output is correct
44 Correct 17 ms 29020 KB Output is correct
45 Correct 702 ms 108776 KB Output is correct
46 Correct 1105 ms 146120 KB Output is correct
47 Correct 1144 ms 146140 KB Output is correct
48 Correct 10 ms 29276 KB Output is correct
49 Correct 9 ms 29208 KB Output is correct
50 Correct 9 ms 29276 KB Output is correct
51 Incorrect 9 ms 29276 KB Possible tampering with the output
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 28508 KB Output is correct
2 Correct 11 ms 28508 KB Output is correct
3 Correct 11 ms 28508 KB Output is correct
4 Correct 13 ms 28508 KB Output is correct
5 Correct 12 ms 28504 KB Output is correct
6 Correct 12 ms 28504 KB Output is correct
7 Correct 18 ms 28508 KB Output is correct
8 Correct 12 ms 28504 KB Output is correct
9 Correct 689 ms 119488 KB Output is correct
10 Correct 50 ms 37636 KB Output is correct
11 Correct 296 ms 77516 KB Output is correct
12 Correct 77 ms 42160 KB Output is correct
13 Correct 54 ms 36720 KB Output is correct
14 Correct 15 ms 28764 KB Output is correct
15 Correct 19 ms 28848 KB Output is correct
16 Correct 729 ms 119500 KB Output is correct
17 Correct 9 ms 29272 KB Output is correct
18 Correct 8 ms 29272 KB Output is correct
19 Correct 9 ms 29276 KB Output is correct
20 Correct 1655 ms 175868 KB Output is correct
21 Correct 1679 ms 175816 KB Output is correct
22 Correct 1676 ms 175564 KB Output is correct
23 Correct 1211 ms 184524 KB Output is correct
24 Correct 337 ms 47440 KB Output is correct
25 Correct 552 ms 66128 KB Output is correct
26 Correct 459 ms 66036 KB Output is correct
27 Correct 1647 ms 211860 KB Output is correct
28 Correct 1551 ms 211804 KB Output is correct
29 Correct 1604 ms 211788 KB Output is correct
30 Correct 1554 ms 211908 KB Output is correct
31 Correct 9 ms 29272 KB Output is correct
32 Incorrect 72 ms 39684 KB Possible tampering with the output
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 28508 KB Output is correct
2 Correct 11 ms 28508 KB Output is correct
3 Correct 11 ms 28508 KB Output is correct
4 Correct 13 ms 28508 KB Output is correct
5 Correct 12 ms 28504 KB Output is correct
6 Correct 12 ms 28504 KB Output is correct
7 Correct 18 ms 28508 KB Output is correct
8 Correct 12 ms 28504 KB Output is correct
9 Correct 689 ms 119488 KB Output is correct
10 Correct 50 ms 37636 KB Output is correct
11 Correct 296 ms 77516 KB Output is correct
12 Correct 77 ms 42160 KB Output is correct
13 Correct 54 ms 36720 KB Output is correct
14 Correct 15 ms 28764 KB Output is correct
15 Correct 19 ms 28848 KB Output is correct
16 Correct 729 ms 119500 KB Output is correct
17 Correct 1487 ms 212464 KB Output is correct
18 Incorrect 1538 ms 212660 KB Possible tampering with the output
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 28508 KB Output is correct
2 Correct 11 ms 28508 KB Output is correct
3 Correct 11 ms 28508 KB Output is correct
4 Correct 13 ms 28508 KB Output is correct
5 Correct 12 ms 28504 KB Output is correct
6 Correct 12 ms 28504 KB Output is correct
7 Correct 18 ms 28508 KB Output is correct
8 Correct 12 ms 28504 KB Output is correct
9 Correct 689 ms 119488 KB Output is correct
10 Correct 50 ms 37636 KB Output is correct
11 Correct 296 ms 77516 KB Output is correct
12 Correct 77 ms 42160 KB Output is correct
13 Correct 54 ms 36720 KB Output is correct
14 Correct 15 ms 28764 KB Output is correct
15 Correct 19 ms 28848 KB Output is correct
16 Correct 729 ms 119500 KB Output is correct
17 Correct 16 ms 28508 KB Output is correct
18 Correct 14 ms 28508 KB Output is correct
19 Correct 16 ms 28508 KB Output is correct
20 Correct 14 ms 28508 KB Output is correct
21 Correct 14 ms 28508 KB Output is correct
22 Correct 19 ms 28552 KB Output is correct
23 Correct 1775 ms 180952 KB Output is correct
24 Correct 13 ms 28384 KB Output is correct
25 Correct 16 ms 29532 KB Output is correct
26 Correct 17 ms 29192 KB Output is correct
27 Correct 18 ms 29276 KB Output is correct
28 Correct 512 ms 89520 KB Output is correct
29 Correct 861 ms 125668 KB Output is correct
30 Correct 1218 ms 152264 KB Output is correct
31 Correct 1581 ms 180940 KB Output is correct
32 Correct 13 ms 28504 KB Output is correct
33 Correct 14 ms 28508 KB Output is correct
34 Correct 13 ms 28508 KB Output is correct
35 Correct 14 ms 28624 KB Output is correct
36 Correct 13 ms 28508 KB Output is correct
37 Correct 13 ms 28508 KB Output is correct
38 Correct 13 ms 28504 KB Output is correct
39 Correct 13 ms 28400 KB Output is correct
40 Correct 12 ms 28508 KB Output is correct
41 Correct 14 ms 28508 KB Output is correct
42 Correct 12 ms 28508 KB Output is correct
43 Correct 15 ms 28764 KB Output is correct
44 Correct 17 ms 29020 KB Output is correct
45 Correct 702 ms 108776 KB Output is correct
46 Correct 1105 ms 146120 KB Output is correct
47 Correct 1144 ms 146140 KB Output is correct
48 Correct 10 ms 29276 KB Output is correct
49 Correct 9 ms 29208 KB Output is correct
50 Correct 9 ms 29276 KB Output is correct
51 Incorrect 9 ms 29276 KB Possible tampering with the output
52 Halted 0 ms 0 KB -