답안 #435093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
435093 2021-06-23T01:22:45 Z jamezzz 분수 공원 (IOI21_parks) C++17
45 / 100
591 ms 44300 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 183 ms 21504 KB Output is correct
10 Correct 15 ms 2636 KB Output is correct
11 Correct 83 ms 12244 KB Output is correct
12 Correct 23 ms 3872 KB Output is correct
13 Correct 60 ms 7252 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 172 ms 17704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 183 ms 21504 KB Output is correct
10 Correct 15 ms 2636 KB Output is correct
11 Correct 83 ms 12244 KB Output is correct
12 Correct 23 ms 3872 KB Output is correct
13 Correct 60 ms 7252 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 172 ms 17704 KB Output is correct
17 Incorrect 1 ms 204 KB Tree @(3, 3) appears more than once: for edges on positions 0 and 2
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 183 ms 21504 KB Output is correct
10 Correct 15 ms 2636 KB Output is correct
11 Correct 83 ms 12244 KB Output is correct
12 Correct 23 ms 3872 KB Output is correct
13 Correct 60 ms 7252 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 172 ms 17704 KB Output is correct
17 Incorrect 1 ms 204 KB Tree @(3, 3) appears more than once: for edges on positions 0 and 2
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 183 ms 21504 KB Output is correct
10 Correct 15 ms 2636 KB Output is correct
11 Correct 83 ms 12244 KB Output is correct
12 Correct 23 ms 3872 KB Output is correct
13 Correct 60 ms 7252 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 172 ms 17704 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 561 ms 43900 KB Output is correct
21 Correct 568 ms 40340 KB Output is correct
22 Correct 591 ms 38188 KB Output is correct
23 Correct 373 ms 31924 KB Output is correct
24 Correct 259 ms 15912 KB Output is correct
25 Correct 211 ms 15952 KB Output is correct
26 Correct 223 ms 16092 KB Output is correct
27 Correct 436 ms 25644 KB Output is correct
28 Correct 401 ms 25720 KB Output is correct
29 Correct 584 ms 25704 KB Output is correct
30 Correct 554 ms 25732 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 25 ms 2924 KB Output is correct
33 Correct 87 ms 8164 KB Output is correct
34 Correct 470 ms 40736 KB Output is correct
35 Correct 9 ms 1236 KB Output is correct
36 Correct 40 ms 4420 KB Output is correct
37 Correct 84 ms 8436 KB Output is correct
38 Correct 143 ms 10432 KB Output is correct
39 Correct 223 ms 14252 KB Output is correct
40 Correct 291 ms 18244 KB Output is correct
41 Correct 392 ms 21824 KB Output is correct
42 Correct 484 ms 25720 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 204 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 1 ms 204 KB Output is correct
52 Correct 1 ms 204 KB Output is correct
53 Correct 1 ms 204 KB Output is correct
54 Correct 3 ms 460 KB Output is correct
55 Correct 2 ms 460 KB Output is correct
56 Correct 205 ms 18684 KB Output is correct
57 Correct 295 ms 27536 KB Output is correct
58 Correct 301 ms 26976 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 1 ms 204 KB Output is correct
62 Correct 414 ms 38804 KB Output is correct
63 Correct 452 ms 39156 KB Output is correct
64 Correct 436 ms 41024 KB Output is correct
65 Correct 4 ms 716 KB Output is correct
66 Correct 6 ms 972 KB Output is correct
67 Correct 211 ms 16196 KB Output is correct
68 Correct 306 ms 26148 KB Output is correct
69 Correct 482 ms 31992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 183 ms 21504 KB Output is correct
10 Correct 15 ms 2636 KB Output is correct
11 Correct 83 ms 12244 KB Output is correct
12 Correct 23 ms 3872 KB Output is correct
13 Correct 60 ms 7252 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 172 ms 17704 KB Output is correct
17 Correct 485 ms 44232 KB Output is correct
18 Correct 525 ms 36704 KB Output is correct
19 Correct 536 ms 44184 KB Output is correct
20 Correct 466 ms 37244 KB Output is correct
21 Correct 422 ms 31664 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 52 ms 5600 KB Output is correct
24 Correct 19 ms 2304 KB Output is correct
25 Correct 57 ms 6600 KB Output is correct
26 Correct 135 ms 10504 KB Output is correct
27 Correct 219 ms 18404 KB Output is correct
28 Correct 276 ms 23252 KB Output is correct
29 Correct 345 ms 27496 KB Output is correct
30 Correct 420 ms 32024 KB Output is correct
31 Correct 498 ms 36640 KB Output is correct
32 Correct 472 ms 40524 KB Output is correct
33 Correct 435 ms 44300 KB Output is correct
34 Correct 4 ms 844 KB Output is correct
35 Correct 7 ms 1228 KB Output is correct
36 Correct 177 ms 16560 KB Output is correct
37 Correct 321 ms 25536 KB Output is correct
38 Correct 474 ms 33948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 183 ms 21504 KB Output is correct
10 Correct 15 ms 2636 KB Output is correct
11 Correct 83 ms 12244 KB Output is correct
12 Correct 23 ms 3872 KB Output is correct
13 Correct 60 ms 7252 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 172 ms 17704 KB Output is correct
17 Incorrect 1 ms 204 KB Tree @(3, 3) appears more than once: for edges on positions 0 and 2
18 Halted 0 ms 0 KB -