답안 #678215

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
678215 2023-01-05T10:11:47 Z yellowtoad 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
298 ms 22396 KB
#include <iostream>
#include <vector>
using namespace std;

void build(std::vector<std::vector<int>> b);

int construct(std::vector<std::vector<int>> a) {
	int n = a.size(), cnt = 0, num[1010], cntt[1010], maxx;
    pair<int,int> id[1010];
	std::vector<std::vector<int>> edge;
    vector<vector<vector<int>>> grp;
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (a[i][j] == 3) return 0;
    for (int i = 0; i < n; i++) if (a[i][i] != 1) return 0;
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (a[i][j] != a[j][i]) return 0;
    for (int i = 0; i < n; i++) id[i] = {-1,-1};
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) if (a[i][j]) if (id[i].first != id[j].first) return 0;
        if (id[i].first == -1) {
            id[i].first = cnt++;
            maxx = 0;
            for (int j = i+1; j < n; j++) if (a[i][j]) id[j].first = id[i].first;
            for (int j = i+1; j < n; j++) maxx = max(maxx,a[i][j]);
            num[cnt-1] = maxx;
        }
        for (int j = 0; j < n; j++) if (id[i].first == id[j].first) if (!a[i][j]) return 0;
        if (id[i].second != -1) {
            for (int j = 0; j < n; j++) {
                if (id[j].first == id[i].first) {
                    if (id[j].second == id[i].second) {
                        if (a[i][j] != 1) return 0;
                    } else if (a[i][j] != num[id[i].first]) return 0;
                }
            }
        } else {
            id[i].second = cntt[id[i].first]++;
            for (int j = 0; j < n; j++) {
                if (id[j].first == id[i].first) {
                    if (a[i][j] == 1) id[j].second = id[i].second;
                    if (id[j].second != id[i].second) {
                        if (a[i][j] != num[id[i].first]) return 0;
                    }
                }
            }
        }
    }
    for (int i = 0; i < cnt; i++) {
        if (num[i] == 1) {
            if (cntt[i] != 1) return 0;
        } else if (num[i] >= 2) {
            if (cntt[i] <= num[i]) return 0;
        }
    }
    for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		edge.push_back(row);
	}
    for (int i = 0; i < cnt; i++) {
        std::vector<vector<int>> row;
		row.resize(cntt[i]);
		grp.push_back(row);
    }
    for (int i = 0; i < n; i++) grp[id[i].first][id[i].second].push_back(i);
    for (int i = 0; i < cnt; i++) {
        for (int j = 0; j < cntt[i]; j++) {
            for (int k = 1; k < grp[i][j].size(); k++) {
                edge[grp[i][j][k-1]][grp[i][j][k]] = 1;
                edge[grp[i][j][k]][grp[i][j][k-1]] = 1;
            }
        }
    }
    for (int i = 0; i < cnt; i++) {
        if (num[i] >= 2) {
            for (int j = 1; j < cntt[i]; j++) {
                edge[grp[i][j][0]][grp[i][j-1][0]] = 1;
                edge[grp[i][j-1][0]][grp[i][j][0]] = 1;
            }
            edge[grp[i][cntt[i]-1][0]][grp[i][0][0]] = 1;
            edge[grp[i][0][0]][grp[i][cntt[i]-1][0]] = 1;
        }
    }
	build(edge);
	return 1;
}

#ifdef EVEL
namespace var{
	std::vector<std::vector<int>> b;
};

void build(std::vector<std::vector<int>> b) {
    var::b = b;
}

int main() {
	int n;
    scanf("%d", &n);
    std::vector<std::vector<int>> p;
    
    p.resize(n);
    for (int i = 0; i < n; i++) {
        p[i].resize(n);
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            scanf("%d", &p[i][j]);
        }
    }

    int possible = construct(p);

    printf("%d\n", possible);
    if (possible == 1) {
        for (int i = 0; i < var::b.size(); i++) {
            for (int j = 0; j < var::b[i].size(); j++) {
                if (j) {
                    printf(" ");
                }
                printf("%d", var::b[i][j]);
            }
            printf("\n");
        }
    }
}
#endif

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:66:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |             for (int k = 1; k < grp[i][j].size(); k++) {
      |                             ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1208 KB Output is correct
7 Correct 178 ms 22268 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1208 KB Output is correct
7 Correct 178 ms 22268 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 11 ms 1232 KB Output is correct
13 Correct 183 ms 22316 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 596 KB Output is correct
17 Correct 104 ms 8328 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 51 ms 5932 KB Output is correct
21 Correct 215 ms 22236 KB Output is correct
22 Correct 179 ms 22324 KB Output is correct
23 Correct 227 ms 22220 KB Output is correct
24 Correct 165 ms 22320 KB Output is correct
25 Correct 97 ms 8396 KB Output is correct
26 Correct 114 ms 8324 KB Output is correct
27 Correct 281 ms 22240 KB Output is correct
28 Correct 182 ms 22324 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 8 ms 1204 KB Output is correct
9 Correct 189 ms 22324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 13 ms 1256 KB Output is correct
13 Correct 220 ms 22372 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 4 ms 668 KB Output is correct
17 Correct 76 ms 8340 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 48 ms 5892 KB Output is correct
22 Correct 209 ms 22396 KB Output is correct
23 Correct 233 ms 22368 KB Output is correct
24 Correct 212 ms 22324 KB Output is correct
25 Correct 81 ms 8400 KB Output is correct
26 Correct 77 ms 8344 KB Output is correct
27 Correct 190 ms 22272 KB Output is correct
28 Correct 298 ms 22356 KB Output is correct
29 Correct 82 ms 8320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 76 ms 5852 KB Output is correct
5 Correct 245 ms 22304 KB Output is correct
6 Correct 191 ms 22352 KB Output is correct
7 Correct 219 ms 22276 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 69 ms 5948 KB Output is correct
10 Correct 187 ms 22260 KB Output is correct
11 Correct 194 ms 22380 KB Output is correct
12 Correct 209 ms 22348 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 49 ms 5852 KB Output is correct
17 Correct 198 ms 22272 KB Output is correct
18 Correct 186 ms 22340 KB Output is correct
19 Correct 221 ms 22252 KB Output is correct
20 Correct 203 ms 22364 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1208 KB Output is correct
7 Correct 178 ms 22268 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 11 ms 1232 KB Output is correct
13 Correct 183 ms 22316 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 596 KB Output is correct
17 Correct 104 ms 8328 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 51 ms 5932 KB Output is correct
21 Correct 215 ms 22236 KB Output is correct
22 Correct 179 ms 22324 KB Output is correct
23 Correct 227 ms 22220 KB Output is correct
24 Correct 165 ms 22320 KB Output is correct
25 Correct 97 ms 8396 KB Output is correct
26 Correct 114 ms 8324 KB Output is correct
27 Correct 281 ms 22240 KB Output is correct
28 Correct 182 ms 22324 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 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 296 KB Output is correct
36 Correct 8 ms 1204 KB Output is correct
37 Correct 189 ms 22324 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 13 ms 1256 KB Output is correct
41 Correct 220 ms 22372 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 304 KB Output is correct
44 Correct 4 ms 668 KB Output is correct
45 Correct 76 ms 8340 KB Output is correct
46 Correct 1 ms 300 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 300 KB Output is correct
49 Correct 48 ms 5892 KB Output is correct
50 Correct 209 ms 22396 KB Output is correct
51 Correct 233 ms 22368 KB Output is correct
52 Correct 212 ms 22324 KB Output is correct
53 Correct 81 ms 8400 KB Output is correct
54 Correct 77 ms 8344 KB Output is correct
55 Correct 190 ms 22272 KB Output is correct
56 Correct 298 ms 22356 KB Output is correct
57 Correct 82 ms 8320 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 3 ms 596 KB Output is correct
61 Correct 116 ms 8332 KB Output is correct
62 Correct 1 ms 300 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 45 ms 5868 KB Output is correct
66 Correct 75 ms 8392 KB Output is correct
67 Correct 68 ms 8432 KB Output is correct
68 Correct 105 ms 8428 KB Output is correct
69 Correct 120 ms 8348 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1208 KB Output is correct
7 Correct 178 ms 22268 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 11 ms 1232 KB Output is correct
13 Correct 183 ms 22316 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 596 KB Output is correct
17 Correct 104 ms 8328 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 51 ms 5932 KB Output is correct
21 Correct 215 ms 22236 KB Output is correct
22 Correct 179 ms 22324 KB Output is correct
23 Correct 227 ms 22220 KB Output is correct
24 Correct 165 ms 22320 KB Output is correct
25 Correct 97 ms 8396 KB Output is correct
26 Correct 114 ms 8324 KB Output is correct
27 Correct 281 ms 22240 KB Output is correct
28 Correct 182 ms 22324 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 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 296 KB Output is correct
36 Correct 8 ms 1204 KB Output is correct
37 Correct 189 ms 22324 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 13 ms 1256 KB Output is correct
41 Correct 220 ms 22372 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 304 KB Output is correct
44 Correct 4 ms 668 KB Output is correct
45 Correct 76 ms 8340 KB Output is correct
46 Correct 1 ms 300 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 300 KB Output is correct
49 Correct 48 ms 5892 KB Output is correct
50 Correct 209 ms 22396 KB Output is correct
51 Correct 233 ms 22368 KB Output is correct
52 Correct 212 ms 22324 KB Output is correct
53 Correct 81 ms 8400 KB Output is correct
54 Correct 77 ms 8344 KB Output is correct
55 Correct 190 ms 22272 KB Output is correct
56 Correct 298 ms 22356 KB Output is correct
57 Correct 82 ms 8320 KB Output is correct
58 Correct 1 ms 296 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 76 ms 5852 KB Output is correct
62 Correct 245 ms 22304 KB Output is correct
63 Correct 191 ms 22352 KB Output is correct
64 Correct 219 ms 22276 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 69 ms 5948 KB Output is correct
67 Correct 187 ms 22260 KB Output is correct
68 Correct 194 ms 22380 KB Output is correct
69 Correct 209 ms 22348 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 49 ms 5852 KB Output is correct
74 Correct 198 ms 22272 KB Output is correct
75 Correct 186 ms 22340 KB Output is correct
76 Correct 221 ms 22252 KB Output is correct
77 Correct 203 ms 22364 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 3 ms 596 KB Output is correct
81 Correct 116 ms 8332 KB Output is correct
82 Correct 1 ms 300 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 45 ms 5868 KB Output is correct
86 Correct 75 ms 8392 KB Output is correct
87 Correct 68 ms 8432 KB Output is correct
88 Correct 105 ms 8428 KB Output is correct
89 Correct 120 ms 8348 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 4 ms 596 KB Output is correct
93 Correct 92 ms 8388 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 18 ms 2392 KB Output is correct
98 Correct 74 ms 8344 KB Output is correct
99 Correct 109 ms 8340 KB Output is correct
100 Correct 75 ms 8384 KB Output is correct
101 Correct 91 ms 8352 KB Output is correct
102 Correct 105 ms 8340 KB Output is correct
103 Correct 66 ms 10112 KB Output is correct
104 Correct 64 ms 10100 KB Output is correct
105 Correct 69 ms 10032 KB Output is correct