Submission #1023179

# Submission time Handle Problem Language Result Execution time Memory
1023179 2024-07-14T12:15:52 Z NeroZein Fountain Parks (IOI21_parks) C++17
30 / 100
398 ms 47472 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std; 

const int N = 2e5 + 5;

int p[N];
int sz[N];
vector<pair<int, int>> inY[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;
    inY[vy[i]].emplace_back(vx[i], i); 
  }
  for (int y = 2; y < N; y += 2) {
    sort(inY[y].begin(), inY[y].end());
  }
  set<pair<int, int>> se; 
  vector<int> u, v, a, b;
  for (int y = 2; y < N; y += 2) {
    for (auto [x, i] : inY[y]) {
      if (mp.count({x + 2, y})) {
        int id = mp[{x + 2, y}];
        if (get(id) != get(i)) {
          unite(i, id); 
          u.push_back(i);
          v.push_back(id);
          if (!se.count({x + 1, y - 1})) {
            se.insert({x + 1, y - 1});
            a.push_back(x + 1);
            b.push_back(y - 1);
          } else {
            //assert(!se.count({x + 1, y + 1}));
            if (se.count({x + 1, y + 1})) return 0; 
            se.insert({x + 1, y + 1});
            a.push_back(x + 1);
            b.push_back(y + 1); 
          }
        }
      }
      if (mp.count({x, y + 2})) {
        int id = mp[{x, y + 2}];
        if (get(id) != get(i)) {
          unite(i, id);
          u.push_back(i);
          v.push_back(id);
          if (!se.count({x - 1, y + 1})) {
            se.insert({x - 1, y + 1});
            a.push_back(x - 1);
            b.push_back(y + 1); 
          } else {
            assert(!se.count({x + 1, y + 1}));
            se.insert({x + 1, y + 1});
            a.push_back(x + 1);
            b.push_back(y + 1);
          }
        }
      }
    }
  }
  if (sz[get(0)] != n) {
    return 0;
  }
  build(u, v, a, b); 
  return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 126 ms 26900 KB Output is correct
10 Correct 15 ms 7516 KB Output is correct
11 Correct 56 ms 16780 KB Output is correct
12 Correct 15 ms 8488 KB Output is correct
13 Correct 37 ms 13256 KB Output is correct
14 Correct 3 ms 5208 KB Output is correct
15 Correct 3 ms 5468 KB Output is correct
16 Correct 129 ms 27068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 126 ms 26900 KB Output is correct
10 Correct 15 ms 7516 KB Output is correct
11 Correct 56 ms 16780 KB Output is correct
12 Correct 15 ms 8488 KB Output is correct
13 Correct 37 ms 13256 KB Output is correct
14 Correct 3 ms 5208 KB Output is correct
15 Correct 3 ms 5468 KB Output is correct
16 Correct 129 ms 27068 KB Output is correct
17 Correct 4 ms 4956 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 3 ms 5004 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 2 ms 4952 KB Output is correct
23 Correct 305 ms 45836 KB Output is correct
24 Correct 3 ms 4952 KB Output is correct
25 Correct 4 ms 5212 KB Output is correct
26 Correct 4 ms 5664 KB Output is correct
27 Correct 5 ms 5724 KB Output is correct
28 Correct 100 ms 21228 KB Output is correct
29 Correct 164 ms 29620 KB Output is correct
30 Correct 238 ms 38052 KB Output is correct
31 Correct 294 ms 45936 KB Output is correct
32 Correct 3 ms 4956 KB Output is correct
33 Correct 2 ms 4956 KB Output is correct
34 Correct 3 ms 4956 KB Output is correct
35 Correct 4 ms 4956 KB Output is correct
36 Correct 2 ms 4956 KB Output is correct
37 Correct 2 ms 5144 KB Output is correct
38 Correct 2 ms 4952 KB Output is correct
39 Correct 2 ms 4956 KB Output is correct
40 Correct 3 ms 4956 KB Output is correct
41 Correct 2 ms 4956 KB Output is correct
42 Correct 2 ms 4956 KB Output is correct
43 Correct 4 ms 5468 KB Output is correct
44 Correct 4 ms 5468 KB Output is correct
45 Correct 114 ms 25964 KB Output is correct
46 Correct 193 ms 35492 KB Output is correct
47 Correct 215 ms 35444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 126 ms 26900 KB Output is correct
10 Correct 15 ms 7516 KB Output is correct
11 Correct 56 ms 16780 KB Output is correct
12 Correct 15 ms 8488 KB Output is correct
13 Correct 37 ms 13256 KB Output is correct
14 Correct 3 ms 5208 KB Output is correct
15 Correct 3 ms 5468 KB Output is correct
16 Correct 129 ms 27068 KB Output is correct
17 Correct 4 ms 4956 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 3 ms 5004 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 2 ms 4952 KB Output is correct
23 Correct 305 ms 45836 KB Output is correct
24 Correct 3 ms 4952 KB Output is correct
25 Correct 4 ms 5212 KB Output is correct
26 Correct 4 ms 5664 KB Output is correct
27 Correct 5 ms 5724 KB Output is correct
28 Correct 100 ms 21228 KB Output is correct
29 Correct 164 ms 29620 KB Output is correct
30 Correct 238 ms 38052 KB Output is correct
31 Correct 294 ms 45936 KB Output is correct
32 Correct 3 ms 4956 KB Output is correct
33 Correct 2 ms 4956 KB Output is correct
34 Correct 3 ms 4956 KB Output is correct
35 Correct 4 ms 4956 KB Output is correct
36 Correct 2 ms 4956 KB Output is correct
37 Correct 2 ms 5144 KB Output is correct
38 Correct 2 ms 4952 KB Output is correct
39 Correct 2 ms 4956 KB Output is correct
40 Correct 3 ms 4956 KB Output is correct
41 Correct 2 ms 4956 KB Output is correct
42 Correct 2 ms 4956 KB Output is correct
43 Correct 4 ms 5468 KB Output is correct
44 Correct 4 ms 5468 KB Output is correct
45 Correct 114 ms 25964 KB Output is correct
46 Correct 193 ms 35492 KB Output is correct
47 Correct 215 ms 35444 KB Output is correct
48 Correct 2 ms 4956 KB Output is correct
49 Correct 3 ms 4956 KB Output is correct
50 Correct 2 ms 4956 KB Output is correct
51 Correct 2 ms 4956 KB Output is correct
52 Correct 2 ms 4956 KB Output is correct
53 Correct 2 ms 4956 KB Output is correct
54 Correct 3 ms 4956 KB Output is correct
55 Correct 324 ms 47232 KB Output is correct
56 Correct 3 ms 4956 KB Output is correct
57 Correct 4 ms 5464 KB Output is correct
58 Correct 11 ms 6508 KB Output is correct
59 Correct 10 ms 6744 KB Output is correct
60 Correct 126 ms 26240 KB Output is correct
61 Correct 199 ms 33700 KB Output is correct
62 Correct 269 ms 40104 KB Output is correct
63 Correct 323 ms 47472 KB Output is correct
64 Correct 2 ms 4956 KB Output is correct
65 Correct 2 ms 4956 KB Output is correct
66 Correct 2 ms 4956 KB Output is correct
67 Correct 302 ms 45736 KB Output is correct
68 Correct 314 ms 45732 KB Output is correct
69 Correct 289 ms 45692 KB Output is correct
70 Correct 5 ms 5724 KB Output is correct
71 Correct 9 ms 6412 KB Output is correct
72 Correct 145 ms 25468 KB Output is correct
73 Correct 210 ms 35932 KB Output is correct
74 Correct 352 ms 46256 KB Output is correct
75 Correct 310 ms 46500 KB Output is correct
76 Correct 298 ms 45704 KB Output is correct
77 Correct 6 ms 5976 KB Output is correct
78 Correct 10 ms 6748 KB Output is correct
79 Correct 128 ms 25564 KB Output is correct
80 Correct 235 ms 36060 KB Output is correct
81 Correct 302 ms 46500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 126 ms 26900 KB Output is correct
10 Correct 15 ms 7516 KB Output is correct
11 Correct 56 ms 16780 KB Output is correct
12 Correct 15 ms 8488 KB Output is correct
13 Correct 37 ms 13256 KB Output is correct
14 Correct 3 ms 5208 KB Output is correct
15 Correct 3 ms 5468 KB Output is correct
16 Correct 129 ms 27068 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 2 ms 5004 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 314 ms 46576 KB Output is correct
21 Correct 282 ms 46756 KB Output is correct
22 Correct 307 ms 46768 KB Output is correct
23 Correct 227 ms 39096 KB Output is correct
24 Correct 230 ms 25936 KB Output is correct
25 Correct 291 ms 38492 KB Output is correct
26 Correct 312 ms 38380 KB Output is correct
27 Correct 398 ms 44708 KB Output is correct
28 Correct 351 ms 44708 KB Output is correct
29 Correct 334 ms 44228 KB Output is correct
30 Correct 328 ms 44200 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Runtime error 12 ms 12944 KB Execution killed with signal 6
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 126 ms 26900 KB Output is correct
10 Correct 15 ms 7516 KB Output is correct
11 Correct 56 ms 16780 KB Output is correct
12 Correct 15 ms 8488 KB Output is correct
13 Correct 37 ms 13256 KB Output is correct
14 Correct 3 ms 5208 KB Output is correct
15 Correct 3 ms 5468 KB Output is correct
16 Correct 129 ms 27068 KB Output is correct
17 Correct 287 ms 45504 KB Output is correct
18 Correct 293 ms 45496 KB Output is correct
19 Correct 304 ms 46760 KB Output is correct
20 Correct 357 ms 43432 KB Output is correct
21 Correct 306 ms 40452 KB Output is correct
22 Correct 3 ms 4956 KB Output is correct
23 Runtime error 22 ms 16876 KB Execution killed with signal 6
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 126 ms 26900 KB Output is correct
10 Correct 15 ms 7516 KB Output is correct
11 Correct 56 ms 16780 KB Output is correct
12 Correct 15 ms 8488 KB Output is correct
13 Correct 37 ms 13256 KB Output is correct
14 Correct 3 ms 5208 KB Output is correct
15 Correct 3 ms 5468 KB Output is correct
16 Correct 129 ms 27068 KB Output is correct
17 Correct 4 ms 4956 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 3 ms 5004 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 2 ms 4952 KB Output is correct
23 Correct 305 ms 45836 KB Output is correct
24 Correct 3 ms 4952 KB Output is correct
25 Correct 4 ms 5212 KB Output is correct
26 Correct 4 ms 5664 KB Output is correct
27 Correct 5 ms 5724 KB Output is correct
28 Correct 100 ms 21228 KB Output is correct
29 Correct 164 ms 29620 KB Output is correct
30 Correct 238 ms 38052 KB Output is correct
31 Correct 294 ms 45936 KB Output is correct
32 Correct 3 ms 4956 KB Output is correct
33 Correct 2 ms 4956 KB Output is correct
34 Correct 3 ms 4956 KB Output is correct
35 Correct 4 ms 4956 KB Output is correct
36 Correct 2 ms 4956 KB Output is correct
37 Correct 2 ms 5144 KB Output is correct
38 Correct 2 ms 4952 KB Output is correct
39 Correct 2 ms 4956 KB Output is correct
40 Correct 3 ms 4956 KB Output is correct
41 Correct 2 ms 4956 KB Output is correct
42 Correct 2 ms 4956 KB Output is correct
43 Correct 4 ms 5468 KB Output is correct
44 Correct 4 ms 5468 KB Output is correct
45 Correct 114 ms 25964 KB Output is correct
46 Correct 193 ms 35492 KB Output is correct
47 Correct 215 ms 35444 KB Output is correct
48 Correct 2 ms 4956 KB Output is correct
49 Correct 3 ms 4956 KB Output is correct
50 Correct 2 ms 4956 KB Output is correct
51 Correct 2 ms 4956 KB Output is correct
52 Correct 2 ms 4956 KB Output is correct
53 Correct 2 ms 4956 KB Output is correct
54 Correct 3 ms 4956 KB Output is correct
55 Correct 324 ms 47232 KB Output is correct
56 Correct 3 ms 4956 KB Output is correct
57 Correct 4 ms 5464 KB Output is correct
58 Correct 11 ms 6508 KB Output is correct
59 Correct 10 ms 6744 KB Output is correct
60 Correct 126 ms 26240 KB Output is correct
61 Correct 199 ms 33700 KB Output is correct
62 Correct 269 ms 40104 KB Output is correct
63 Correct 323 ms 47472 KB Output is correct
64 Correct 2 ms 4956 KB Output is correct
65 Correct 2 ms 4956 KB Output is correct
66 Correct 2 ms 4956 KB Output is correct
67 Correct 302 ms 45736 KB Output is correct
68 Correct 314 ms 45732 KB Output is correct
69 Correct 289 ms 45692 KB Output is correct
70 Correct 5 ms 5724 KB Output is correct
71 Correct 9 ms 6412 KB Output is correct
72 Correct 145 ms 25468 KB Output is correct
73 Correct 210 ms 35932 KB Output is correct
74 Correct 352 ms 46256 KB Output is correct
75 Correct 310 ms 46500 KB Output is correct
76 Correct 298 ms 45704 KB Output is correct
77 Correct 6 ms 5976 KB Output is correct
78 Correct 10 ms 6748 KB Output is correct
79 Correct 128 ms 25564 KB Output is correct
80 Correct 235 ms 36060 KB Output is correct
81 Correct 302 ms 46500 KB Output is correct
82 Correct 3 ms 4956 KB Output is correct
83 Correct 2 ms 5004 KB Output is correct
84 Correct 2 ms 4956 KB Output is correct
85 Correct 314 ms 46576 KB Output is correct
86 Correct 282 ms 46756 KB Output is correct
87 Correct 307 ms 46768 KB Output is correct
88 Correct 227 ms 39096 KB Output is correct
89 Correct 230 ms 25936 KB Output is correct
90 Correct 291 ms 38492 KB Output is correct
91 Correct 312 ms 38380 KB Output is correct
92 Correct 398 ms 44708 KB Output is correct
93 Correct 351 ms 44708 KB Output is correct
94 Correct 334 ms 44228 KB Output is correct
95 Correct 328 ms 44200 KB Output is correct
96 Correct 2 ms 4956 KB Output is correct
97 Runtime error 12 ms 12944 KB Execution killed with signal 6
98 Halted 0 ms 0 KB -