Submission #1047760

# Submission time Handle Problem Language Result Execution time Memory
1047760 2024-08-07T15:42:51 Z CISM Fountain Parks (IOI21_parks) C++17
45 / 100
277 ms 46760 KB
#include "parks.h"

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

constexpr int kDirX[] = {0, 2, 0, -2};
constexpr int kDirY[] = {2, 0, -2, 0};

int construct_roads(std::vector<int> X, std::vector<int> Y) {
  int N = X.size();

  map<pair<int, int>, int> pos;
  for (int i = 0; i < N; ++i) {
    pos[make_pair(X[i], Y[i])] = i;
  }

  vector<bool> visited(N, false);
  vector<int> U, V, A, B;

  function<void (int)> dfs = [&] (int u) {
    for (int dir = 0; dir < 4; ++dir) {
      if (pos.count(make_pair(X[u] + kDirX[dir], Y[u] + kDirY[dir]))) {
        int v = pos[make_pair(X[u] + kDirX[dir], Y[u] + kDirY[dir])];
        if (!visited[v]) {
          U.push_back(u);
          V.push_back(v);

          //    |
          //  ^ |->
          //  | |
          // ---0---
          //    | |
          //  <-| v
          //    |
          bool odd = (X[u] + Y[u]) & 2;

          if (X[u] == X[v]) {
            B.push_back(Y[u] + (Y[u] < Y[v] ? 1 : -1));
            A.push_back(X[u] + (odd ^ (Y[u] < Y[v]) ? 1 : -1));
          } else {
            A.push_back(X[u] + (X[u] < X[v] ? 1 : -1));
            B.push_back(Y[u] + (odd ^ (X[u] < X[v]) ? -1 : 1));
          }
          visited[v] = true;
          dfs(v);
        }
      }
    }
  };

  visited[0] = true;
  dfs(0);

  if (all_of(visited.begin(), visited.end(), [](bool b) { return b; })) {
    build(U, V, A, B);
    return 1;  
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 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 432 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 76 ms 22352 KB Output is correct
10 Correct 6 ms 2904 KB Output is correct
11 Correct 41 ms 12672 KB Output is correct
12 Correct 10 ms 3928 KB Output is correct
13 Correct 22 ms 7772 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 76 ms 18644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 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 432 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 76 ms 22352 KB Output is correct
10 Correct 6 ms 2904 KB Output is correct
11 Correct 41 ms 12672 KB Output is correct
12 Correct 10 ms 3928 KB Output is correct
13 Correct 22 ms 7772 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 76 ms 18644 KB Output is correct
17 Incorrect 0 ms 344 KB Tree @(3, 3) appears more than once: for edges on positions 0 and 2
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 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 432 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 76 ms 22352 KB Output is correct
10 Correct 6 ms 2904 KB Output is correct
11 Correct 41 ms 12672 KB Output is correct
12 Correct 10 ms 3928 KB Output is correct
13 Correct 22 ms 7772 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 76 ms 18644 KB Output is correct
17 Incorrect 0 ms 344 KB Tree @(3, 3) appears more than once: for edges on positions 0 and 2
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 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 432 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 76 ms 22352 KB Output is correct
10 Correct 6 ms 2904 KB Output is correct
11 Correct 41 ms 12672 KB Output is correct
12 Correct 10 ms 3928 KB Output is correct
13 Correct 22 ms 7772 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 76 ms 18644 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 408 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 228 ms 46452 KB Output is correct
21 Correct 216 ms 42668 KB Output is correct
22 Correct 203 ms 40360 KB Output is correct
23 Correct 176 ms 33724 KB Output is correct
24 Correct 81 ms 17804 KB Output is correct
25 Correct 85 ms 17592 KB Output is correct
26 Correct 104 ms 17648 KB Output is correct
27 Correct 187 ms 27424 KB Output is correct
28 Correct 174 ms 27512 KB Output is correct
29 Correct 277 ms 27512 KB Output is correct
30 Correct 244 ms 27308 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 14 ms 3272 KB Output is correct
33 Correct 36 ms 9308 KB Output is correct
34 Correct 196 ms 43288 KB Output is correct
35 Correct 4 ms 1368 KB Output is correct
36 Correct 20 ms 5200 KB Output is correct
37 Correct 40 ms 9812 KB Output is correct
38 Correct 68 ms 11780 KB Output is correct
39 Correct 100 ms 15800 KB Output is correct
40 Correct 125 ms 20160 KB Output is correct
41 Correct 155 ms 23892 KB Output is correct
42 Correct 195 ms 28280 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 83 ms 19736 KB Output is correct
57 Correct 136 ms 28860 KB Output is correct
58 Correct 128 ms 28328 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 189 ms 40448 KB Output is correct
63 Correct 175 ms 40736 KB Output is correct
64 Correct 181 ms 43084 KB Output is correct
65 Correct 2 ms 860 KB Output is correct
66 Correct 3 ms 1116 KB Output is correct
67 Correct 91 ms 17012 KB Output is correct
68 Correct 156 ms 27456 KB Output is correct
69 Correct 199 ms 33668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 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 432 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 76 ms 22352 KB Output is correct
10 Correct 6 ms 2904 KB Output is correct
11 Correct 41 ms 12672 KB Output is correct
12 Correct 10 ms 3928 KB Output is correct
13 Correct 22 ms 7772 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 76 ms 18644 KB Output is correct
17 Correct 206 ms 46740 KB Output is correct
18 Correct 198 ms 39060 KB Output is correct
19 Correct 198 ms 46760 KB Output is correct
20 Correct 193 ms 38848 KB Output is correct
21 Correct 188 ms 32980 KB Output is correct
22 Correct 0 ms 436 KB Output is correct
23 Correct 30 ms 6156 KB Output is correct
24 Correct 10 ms 2628 KB Output is correct
25 Correct 31 ms 7644 KB Output is correct
26 Correct 59 ms 12020 KB Output is correct
27 Correct 100 ms 19764 KB Output is correct
28 Correct 139 ms 25032 KB Output is correct
29 Correct 171 ms 29568 KB Output is correct
30 Correct 206 ms 33960 KB Output is correct
31 Correct 228 ms 39364 KB Output is correct
32 Correct 210 ms 42180 KB Output is correct
33 Correct 207 ms 46112 KB Output is correct
34 Correct 3 ms 860 KB Output is correct
35 Correct 4 ms 1372 KB Output is correct
36 Correct 90 ms 17536 KB Output is correct
37 Correct 137 ms 26644 KB Output is correct
38 Correct 190 ms 35628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 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 432 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 76 ms 22352 KB Output is correct
10 Correct 6 ms 2904 KB Output is correct
11 Correct 41 ms 12672 KB Output is correct
12 Correct 10 ms 3928 KB Output is correct
13 Correct 22 ms 7772 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 76 ms 18644 KB Output is correct
17 Incorrect 0 ms 344 KB Tree @(3, 3) appears more than once: for edges on positions 0 and 2
18 Halted 0 ms 0 KB -