답안 #1062262

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1062262 2024-08-16T23:01:52 Z wood 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
205 ms 22100 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vi vector<int>
#define vp32 vector<p32>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MOD %1000000007
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
using Tree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//never guess
//never debug without reviewing code
//never try adding ones or substracting them
//only step by step debug when necessay



int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
    vector<vi> res(n,vi(n));
    int leader[n]; for(int i = 0; i<n; i++) leader[i] = i;
    bool done[n]; memset(done,0,sizeof done);
    for(int i = 0; i<n; i++){
        for(int j = 0; j<n; j++){
            if(p[i][j]==3) return 0;
        }
    }
    for(int i = 0; i<n; i++){
        if(done[i])continue;
        done[i] = true;
        set<int> zeros, ones, twos;
        for(int j = 0; j<n; j++){
            if(p[i][j]==0) zeros.insert(j);
            else if(p[i][j]==1){
              ones.insert(j);
              done[j] = true;
            }
            else twos.insert(j);
        }
        for(int x : ones){
            for(int j = 0; j<n; j++)
                if((p[x][j]==0&&!zeros.count(j))||(p[x][j]==1&&!ones.count(j))||(p[x][j]==2&&!twos.count(j))) return 0;
        }
        vi comp(ones.begin(),ones.end());
        for(int j = 0; j<comp.size()-1; j++){
            int a = comp[j], b = comp[j+1];
            res[a][b] = res[b][a] = 1;
            leader[b] = i;
        }
    }
    memset(done,0,sizeof done);
    for(int ii = 0; ii<n; ii++){
        int i = leader[ii];
        if(done[i]) continue;
        done[i] = true;
        set<int> t = {i};
        for(int k = 0; k<n; k++){
            int j = leader[k];
            if(p[i][j]==2){ t.insert(j); done[j] = true;}
        }
        if(t.size()==2) return 0;
        if(t.size()<=1) continue;
        for(int x : t){
            for(int k = 0; k<n; k++){
                int j = leader[k];
                if((p[x][j]==2&&!t.count(j))||(p[x][j]==0&&t.count(j))) return 0;
            }
        }
        vi comp(t.begin(),t.end());
        for(int j = 0; j<comp.size()-1; j++){
            int a = comp[j], b = comp[j+1];
            res[a][b] = res[b][a] = 1;
        }
        int a = comp[0], b = comp[comp.size()-1];
        res[a][b] = res[b][a] = 1;
    }
    build(res);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:55:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int j = 0; j<comp.size()-1; j++){
      |                        ~^~~~~~~~~~~~~~
supertrees.cpp:80:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |         for(int j = 0; j<comp.size()-1; j++){
      |                        ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 348 KB Output is correct
6 Correct 6 ms 1116 KB Output is correct
7 Correct 124 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 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 348 KB Output is correct
6 Correct 6 ms 1116 KB Output is correct
7 Correct 124 ms 22100 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 171 ms 22044 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 76 ms 12300 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 32 ms 5724 KB Output is correct
21 Correct 123 ms 22096 KB Output is correct
22 Correct 139 ms 22100 KB Output is correct
23 Correct 127 ms 22100 KB Output is correct
24 Correct 165 ms 22020 KB Output is correct
25 Correct 57 ms 12116 KB Output is correct
26 Correct 49 ms 12116 KB Output is correct
27 Correct 126 ms 22040 KB Output is correct
28 Correct 171 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 7 ms 1112 KB Output is correct
9 Correct 167 ms 22096 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 8 ms 1112 KB Output is correct
13 Correct 182 ms 22040 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 5 ms 860 KB Output is correct
17 Correct 151 ms 12328 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 45 ms 5748 KB Output is correct
22 Correct 196 ms 22100 KB Output is correct
23 Correct 188 ms 22040 KB Output is correct
24 Correct 203 ms 22096 KB Output is correct
25 Correct 108 ms 12112 KB Output is correct
26 Correct 123 ms 12112 KB Output is correct
27 Correct 186 ms 22040 KB Output is correct
28 Correct 205 ms 22096 KB Output is correct
29 Correct 108 ms 12116 KB Output is correct
# 결과 실행 시간 메모리 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 31 ms 5780 KB Output is correct
5 Correct 121 ms 21972 KB Output is correct
6 Correct 141 ms 22100 KB Output is correct
7 Correct 129 ms 22096 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 43 ms 5716 KB Output is correct
10 Correct 198 ms 22040 KB Output is correct
11 Correct 179 ms 22040 KB Output is correct
12 Correct 194 ms 22096 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 43 ms 5740 KB Output is correct
17 Correct 198 ms 22100 KB Output is correct
18 Correct 179 ms 22100 KB Output is correct
19 Correct 162 ms 22024 KB Output is correct
20 Correct 176 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 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 348 KB Output is correct
6 Correct 6 ms 1116 KB Output is correct
7 Correct 124 ms 22100 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 171 ms 22044 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 76 ms 12300 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 32 ms 5724 KB Output is correct
21 Correct 123 ms 22096 KB Output is correct
22 Correct 139 ms 22100 KB Output is correct
23 Correct 127 ms 22100 KB Output is correct
24 Correct 165 ms 22020 KB Output is correct
25 Correct 57 ms 12116 KB Output is correct
26 Correct 49 ms 12116 KB Output is correct
27 Correct 126 ms 22040 KB Output is correct
28 Correct 171 ms 22100 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 7 ms 1112 KB Output is correct
37 Correct 167 ms 22096 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 8 ms 1112 KB Output is correct
41 Correct 182 ms 22040 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 5 ms 860 KB Output is correct
45 Correct 151 ms 12328 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 45 ms 5748 KB Output is correct
50 Correct 196 ms 22100 KB Output is correct
51 Correct 188 ms 22040 KB Output is correct
52 Correct 203 ms 22096 KB Output is correct
53 Correct 108 ms 12112 KB Output is correct
54 Correct 123 ms 12112 KB Output is correct
55 Correct 186 ms 22040 KB Output is correct
56 Correct 205 ms 22096 KB Output is correct
57 Correct 108 ms 12116 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 2 ms 860 KB Output is correct
61 Correct 53 ms 12312 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 42 ms 5732 KB Output is correct
66 Correct 62 ms 12112 KB Output is correct
67 Correct 55 ms 12112 KB Output is correct
68 Correct 59 ms 12224 KB Output is correct
69 Correct 104 ms 12308 KB Output is correct
# 결과 실행 시간 메모리 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 348 KB Output is correct
6 Correct 6 ms 1116 KB Output is correct
7 Correct 124 ms 22100 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 171 ms 22044 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 76 ms 12300 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 32 ms 5724 KB Output is correct
21 Correct 123 ms 22096 KB Output is correct
22 Correct 139 ms 22100 KB Output is correct
23 Correct 127 ms 22100 KB Output is correct
24 Correct 165 ms 22020 KB Output is correct
25 Correct 57 ms 12116 KB Output is correct
26 Correct 49 ms 12116 KB Output is correct
27 Correct 126 ms 22040 KB Output is correct
28 Correct 171 ms 22100 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 7 ms 1112 KB Output is correct
37 Correct 167 ms 22096 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 8 ms 1112 KB Output is correct
41 Correct 182 ms 22040 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 5 ms 860 KB Output is correct
45 Correct 151 ms 12328 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 45 ms 5748 KB Output is correct
50 Correct 196 ms 22100 KB Output is correct
51 Correct 188 ms 22040 KB Output is correct
52 Correct 203 ms 22096 KB Output is correct
53 Correct 108 ms 12112 KB Output is correct
54 Correct 123 ms 12112 KB Output is correct
55 Correct 186 ms 22040 KB Output is correct
56 Correct 205 ms 22096 KB Output is correct
57 Correct 108 ms 12116 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 31 ms 5780 KB Output is correct
62 Correct 121 ms 21972 KB Output is correct
63 Correct 141 ms 22100 KB Output is correct
64 Correct 129 ms 22096 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 43 ms 5716 KB Output is correct
67 Correct 198 ms 22040 KB Output is correct
68 Correct 179 ms 22040 KB Output is correct
69 Correct 194 ms 22096 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 43 ms 5740 KB Output is correct
74 Correct 198 ms 22100 KB Output is correct
75 Correct 179 ms 22100 KB Output is correct
76 Correct 162 ms 22024 KB Output is correct
77 Correct 176 ms 22100 KB Output is correct
78 Correct 0 ms 344 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 2 ms 860 KB Output is correct
81 Correct 53 ms 12312 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 42 ms 5732 KB Output is correct
86 Correct 62 ms 12112 KB Output is correct
87 Correct 55 ms 12112 KB Output is correct
88 Correct 59 ms 12224 KB Output is correct
89 Correct 104 ms 12308 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 3 ms 860 KB Output is correct
93 Correct 55 ms 12052 KB Output is correct
94 Correct 0 ms 344 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 12 ms 3708 KB Output is correct
98 Correct 49 ms 14164 KB Output is correct
99 Correct 49 ms 14212 KB Output is correct
100 Correct 47 ms 14164 KB Output is correct
101 Correct 47 ms 14164 KB Output is correct
102 Correct 47 ms 14148 KB Output is correct
103 Correct 48 ms 14160 KB Output is correct
104 Correct 48 ms 14084 KB Output is correct
105 Correct 56 ms 14160 KB Output is correct