답안 #826971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826971 2023-08-16T07:39:17 Z erray 슈퍼트리 잇기 (IOI20_supertrees) C++17
96 / 100
179 ms 24156 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG
  #include "/home/eagle/ioi19/day2/debug.h"
#else 
  #define debug(...) void(37)
#endif

int construct(std::vector<std::vector<int>> P) {
	int N = int(P.size());
  vector<vector<int>> ans(N, vector<int>(N));
  auto Add = [&](int x, int y) {
    ans[x][y] = ans[y][x] = true;
  };
  bool bad = false;
  auto Group = [&](vector<int> s, function<bool(int)> connected) {
    int c = int(s.size());
    vector<int> used(c, -1);
    vector<vector<int>> gs;
    for (int i = 0; i < c; ++i) {
      if (used[i] != -1) {
        continue;
      }
      used[i] = i;
      gs.push_back({s[i]});
      for (int j = i + 1; j < c; ++j) {
        if (connected(P[s[i]][s[j]])) {
          if (used[j] != -1) {
            bad = true;
          }
          used[j] = i;
          gs.back().push_back(s[j]);
        }
      }
    }
    for (int i = 0; i < c; ++i) {
      for (int j = 0; j < c; ++j) {
        bad |= connected(P[s[i]][s[j]]) != (used[i] == used[j]);
      }
    }
    return gs;
  };
  vector<int> foo(N);
  iota(foo.begin(), foo.end(), 0);
  auto gs = Group(foo, [&](int x) {
    return x != 0;
  });
  debug(gs);
  for (auto g : gs) {
    bool two = false, three = false;
    for (auto x : g) {
      for (auto y : g) {
        two |= P[x][y] == 2;
        three |= P[x][y] == 3; 
      }
    }
    auto ones = Group(g, [&](int x) {
      return x == 1;
    });
    if ((two && three) || (two && int(ones.size()) < 3) || (three && int(ones.size()) < 4)) {
      bad = true;
      break;
    }
    for (auto o : ones) {
      for (int i = 0; i < int(o.size()) - 1; ++i) {
        Add(o[i], o[i + 1]);
      }
    }
    for (int i = 0; i < int(ones.size()) - 1; ++i) {
      Add(ones[i][0], ones[i + 1][0]);
    }
    if (two || three) {
      Add(ones[0][0], ones.back()[0]);
    }
    if (three) {
      Add(ones[0][0], ones[2][0]);
    }
  }
  if (bad) {
    return 0;
  }
  build(ans);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 157 ms 22444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 157 ms 22444 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1284 KB Output is correct
13 Correct 159 ms 22592 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 792 KB Output is correct
17 Correct 75 ms 12324 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 260 KB Output is correct
20 Correct 38 ms 5900 KB Output is correct
21 Correct 170 ms 22068 KB Output is correct
22 Correct 164 ms 22196 KB Output is correct
23 Correct 165 ms 22204 KB Output is correct
24 Correct 156 ms 22220 KB Output is correct
25 Correct 64 ms 12180 KB Output is correct
26 Correct 69 ms 12448 KB Output is correct
27 Correct 158 ms 22236 KB Output is correct
28 Correct 154 ms 22340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 7 ms 1236 KB Output is correct
9 Correct 155 ms 22440 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1208 KB Output is correct
13 Correct 158 ms 24024 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 824 KB Output is correct
17 Correct 78 ms 14152 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 43 ms 6152 KB Output is correct
22 Correct 156 ms 24016 KB Output is correct
23 Correct 152 ms 23952 KB Output is correct
24 Correct 169 ms 23952 KB Output is correct
25 Correct 64 ms 14068 KB Output is correct
26 Correct 63 ms 14084 KB Output is correct
27 Correct 156 ms 23972 KB Output is correct
28 Correct 162 ms 24012 KB Output is correct
29 Correct 64 ms 14068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 39 ms 5912 KB Output is correct
5 Correct 153 ms 22268 KB Output is correct
6 Correct 168 ms 22240 KB Output is correct
7 Correct 158 ms 22256 KB Output is correct
8 Correct 0 ms 300 KB Output is correct
9 Correct 42 ms 6148 KB Output is correct
10 Correct 171 ms 24156 KB Output is correct
11 Correct 154 ms 23940 KB Output is correct
12 Correct 179 ms 23972 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 300 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 38 ms 6232 KB Output is correct
17 Correct 154 ms 23928 KB Output is correct
18 Correct 157 ms 23960 KB Output is correct
19 Correct 151 ms 23960 KB Output is correct
20 Correct 172 ms 24068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 157 ms 22444 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1284 KB Output is correct
13 Correct 159 ms 22592 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 792 KB Output is correct
17 Correct 75 ms 12324 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 260 KB Output is correct
20 Correct 38 ms 5900 KB Output is correct
21 Correct 170 ms 22068 KB Output is correct
22 Correct 164 ms 22196 KB Output is correct
23 Correct 165 ms 22204 KB Output is correct
24 Correct 156 ms 22220 KB Output is correct
25 Correct 64 ms 12180 KB Output is correct
26 Correct 69 ms 12448 KB Output is correct
27 Correct 158 ms 22236 KB Output is correct
28 Correct 154 ms 22340 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 308 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 155 ms 22440 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 7 ms 1208 KB Output is correct
41 Correct 158 ms 24024 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 4 ms 824 KB Output is correct
45 Correct 78 ms 14152 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 304 KB Output is correct
49 Correct 43 ms 6152 KB Output is correct
50 Correct 156 ms 24016 KB Output is correct
51 Correct 152 ms 23952 KB Output is correct
52 Correct 169 ms 23952 KB Output is correct
53 Correct 64 ms 14068 KB Output is correct
54 Correct 63 ms 14084 KB Output is correct
55 Correct 156 ms 23972 KB Output is correct
56 Correct 162 ms 24012 KB Output is correct
57 Correct 64 ms 14068 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 3 ms 852 KB Output is correct
61 Correct 79 ms 14132 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 39 ms 6180 KB Output is correct
66 Correct 71 ms 14084 KB Output is correct
67 Correct 64 ms 14076 KB Output is correct
68 Correct 63 ms 14072 KB Output is correct
69 Correct 64 ms 14132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 157 ms 22444 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1284 KB Output is correct
13 Correct 159 ms 22592 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 792 KB Output is correct
17 Correct 75 ms 12324 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 260 KB Output is correct
20 Correct 38 ms 5900 KB Output is correct
21 Correct 170 ms 22068 KB Output is correct
22 Correct 164 ms 22196 KB Output is correct
23 Correct 165 ms 22204 KB Output is correct
24 Correct 156 ms 22220 KB Output is correct
25 Correct 64 ms 12180 KB Output is correct
26 Correct 69 ms 12448 KB Output is correct
27 Correct 158 ms 22236 KB Output is correct
28 Correct 154 ms 22340 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 308 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 155 ms 22440 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 7 ms 1208 KB Output is correct
41 Correct 158 ms 24024 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 4 ms 824 KB Output is correct
45 Correct 78 ms 14152 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 304 KB Output is correct
49 Correct 43 ms 6152 KB Output is correct
50 Correct 156 ms 24016 KB Output is correct
51 Correct 152 ms 23952 KB Output is correct
52 Correct 169 ms 23952 KB Output is correct
53 Correct 64 ms 14068 KB Output is correct
54 Correct 63 ms 14084 KB Output is correct
55 Correct 156 ms 23972 KB Output is correct
56 Correct 162 ms 24012 KB Output is correct
57 Correct 64 ms 14068 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 39 ms 5912 KB Output is correct
62 Correct 153 ms 22268 KB Output is correct
63 Correct 168 ms 22240 KB Output is correct
64 Correct 158 ms 22256 KB Output is correct
65 Correct 0 ms 300 KB Output is correct
66 Correct 42 ms 6148 KB Output is correct
67 Correct 171 ms 24156 KB Output is correct
68 Correct 154 ms 23940 KB Output is correct
69 Correct 179 ms 23972 KB Output is correct
70 Correct 0 ms 340 KB Output is correct
71 Correct 0 ms 300 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 38 ms 6232 KB Output is correct
74 Correct 154 ms 23928 KB Output is correct
75 Correct 157 ms 23960 KB Output is correct
76 Correct 151 ms 23960 KB Output is correct
77 Correct 172 ms 24068 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 3 ms 852 KB Output is correct
81 Correct 79 ms 14132 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 39 ms 6180 KB Output is correct
86 Correct 71 ms 14084 KB Output is correct
87 Correct 64 ms 14076 KB Output is correct
88 Correct 63 ms 14072 KB Output is correct
89 Correct 64 ms 14132 KB Output is correct
90 Correct 0 ms 212 KB Output is correct
91 Correct 0 ms 212 KB Output is correct
92 Correct 3 ms 796 KB Output is correct
93 Correct 68 ms 14068 KB Output is correct
94 Correct 0 ms 296 KB Output is correct
95 Correct 0 ms 212 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 20 ms 3696 KB Output is correct
98 Correct 91 ms 14000 KB Output is correct
99 Correct 64 ms 14068 KB Output is correct
100 Correct 62 ms 14072 KB Output is correct
101 Correct 64 ms 14080 KB Output is correct
102 Incorrect 157 ms 23940 KB Answer gives possible 1 while actual possible 0
103 Halted 0 ms 0 KB -