답안 #800085

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
800085 2023-08-01T09:57:29 Z becaido 슈퍼트리 잇기 (IOI20_supertrees) C++17
40 / 100
179 ms 23948 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifndef WAIMAI
#include "supertrees.h"
#endif

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

#ifdef WAIMAI
void build(vector<vector<int>> b);
#endif

const int SIZE = 1005;

int n, mx;
bool vs[SIZE];
vector<vector<int>> ans;

int construct(vector<vector<int>> p) {
	n = p.size();
	ans.resize(n, vector<int>(n));
	FOR (i, 0, n - 1) mx = max(mx, *max_element(p[i].begin(), p[i].end()));
	if (mx == 1) {
        fill(vs, vs + n, 0);
        FOR (i, 0, n - 1) if (!vs[i]) {
            vector<int> all;
            queue<int> q;
            vs[i] = 1, q.push(i);
            while (q.size()) {
                int pos = q.front();
                q.pop();
                all.pb(pos);
                FOR (j, 0, n - 1) if (p[pos][j] && !vs[j]) {
                    q.push(j);
                    vs[j] = 1;
                }
            }
            for (int x : all) for (int y : all) if (!p[x][y]) return 0;
            FOR (j, 1, all.size() - 1) ans[all[j]][all[j - 1]] = ans[all[j - 1]][all[j]] = 1;
        }
        build(ans);
        return 1;
	}
	fill(vs, vs + n, 0);
    FOR (i, 0, n - 1) if (!vs[i]) {
        vector<int> all;
        queue<int> q;
        vs[i] = 1, q.push(i);
        while (q.size()) {
            int pos = q.front();
            q.pop();
            all.pb(pos);
            FOR (j, 0, n - 1) if (p[pos][j] && !vs[j]) {
                q.push(j);
                vs[j] = 1;
            }
        }
        if (all.size() == 1) continue;
        if (all.size() == 2) return 0;
        for (int x : all) for (int y : all) if (!p[x][y]) return 0;
        FOR (j, 1, all.size() - 1) ans[all[j]][all[j - 1]] = ans[all[j - 1]][all[j]] = 1;
        ans[all[0]][all.back()] = ans[all.back()][all[0]] = 1;
    }
    build(ans);
    return 1;
}

/*
in1
4
1 1 2 2
1 1 2 2
2 2 1 2
2 2 2 1
out1
1
0 1 0 0
1 0 1 1
0 1 0 1
0 1 1 0

in2
2
1 0
0 1
out2
1
0 0
0 0

in3
2
1 3
3 1
out3
0
*/

#ifdef WAIMAI
static int nn;
static vector<vector<int>> pp;
static vector<vector<int>> bb;
static bool called = false;

static void check(bool cond, string message) {
    if (!cond) {
        printf("%s\n", message.c_str());
        fclose(stdout);
        exit(0);
    }
}

void build(vector<vector<int>> _b) {
    check(!called, "build is called more than once");
    called = true;
    check((int)_b.size() == nn, "Invalid number of rows in b");
    for (int i = 0; i < nn; i++) {
        check((int)_b[i].size() == nn, "Invalid number of columns in b");
    }
    bb = _b;
}

int main() {
    assert(scanf("%d", &nn) == 1);

    pp.resize(nn);
    for (int i = 0; i < nn; i++) {
        pp[i].resize(nn);
    }

    for (int i = 0; i < nn; i++) {
        for (int j = 0; j < nn; j++) {
            assert(scanf("%d", &pp[i][j]) == 1);
        }
    }
    fclose(stdin);

    int possible = construct(pp);

    check(possible == 0 || possible == 1, "Invalid return value of construct");
    if (possible == 1) {
        check(called, "construct returned 1 without calling build");
    } else {
        check(!called, "construct called build but returned 0");
    }

    printf("%d\n", possible);
    if (possible == 1) {
        for (int i = 0; i < nn; i++) {
            for (int j = 0; j < nn; j++) {
                if (j) {
                    printf(" ");
                }
                printf("%d", bb[i][j]);
            }
            printf("\n");
        }
    }
    fclose(stdout);
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1188 KB Output is correct
7 Correct 147 ms 22020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1188 KB Output is correct
7 Correct 147 ms 22020 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 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 6 ms 1108 KB Output is correct
13 Correct 148 ms 22020 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 70 ms 12052 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 37 ms 5736 KB Output is correct
21 Correct 146 ms 22020 KB Output is correct
22 Correct 146 ms 22076 KB Output is correct
23 Correct 151 ms 22032 KB Output is correct
24 Correct 146 ms 22024 KB Output is correct
25 Correct 62 ms 12052 KB Output is correct
26 Correct 59 ms 12048 KB Output is correct
27 Correct 152 ms 21964 KB Output is correct
28 Correct 157 ms 22028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 6 ms 1236 KB Output is correct
9 Correct 163 ms 23920 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1240 KB Output is correct
13 Correct 150 ms 23676 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 820 KB Output is correct
17 Correct 70 ms 14092 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 38 ms 6184 KB Output is correct
22 Correct 150 ms 23948 KB Output is correct
23 Correct 156 ms 23892 KB Output is correct
24 Correct 149 ms 23888 KB Output is correct
25 Correct 59 ms 14068 KB Output is correct
26 Correct 60 ms 14068 KB Output is correct
27 Correct 179 ms 23920 KB Output is correct
28 Correct 149 ms 23888 KB Output is correct
29 Correct 59 ms 14080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 36 ms 5708 KB Output is correct
5 Correct 151 ms 22032 KB Output is correct
6 Correct 156 ms 22248 KB Output is correct
7 Correct 150 ms 22000 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 36 ms 5720 KB Output is correct
10 Correct 153 ms 21956 KB Output is correct
11 Correct 156 ms 21984 KB Output is correct
12 Correct 151 ms 21992 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Incorrect 0 ms 212 KB Too many ways to get from 4 to 8, should be 1 found no less than 2
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1188 KB Output is correct
7 Correct 147 ms 22020 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 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 6 ms 1108 KB Output is correct
13 Correct 148 ms 22020 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 70 ms 12052 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 37 ms 5736 KB Output is correct
21 Correct 146 ms 22020 KB Output is correct
22 Correct 146 ms 22076 KB Output is correct
23 Correct 151 ms 22032 KB Output is correct
24 Correct 146 ms 22024 KB Output is correct
25 Correct 62 ms 12052 KB Output is correct
26 Correct 59 ms 12048 KB Output is correct
27 Correct 152 ms 21964 KB Output is correct
28 Correct 157 ms 22028 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 296 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 6 ms 1236 KB Output is correct
37 Correct 163 ms 23920 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 6 ms 1240 KB Output is correct
41 Correct 150 ms 23676 KB Output is correct
42 Correct 1 ms 296 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 3 ms 820 KB Output is correct
45 Correct 70 ms 14092 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 38 ms 6184 KB Output is correct
50 Correct 150 ms 23948 KB Output is correct
51 Correct 156 ms 23892 KB Output is correct
52 Correct 149 ms 23888 KB Output is correct
53 Correct 59 ms 14068 KB Output is correct
54 Correct 60 ms 14068 KB Output is correct
55 Correct 179 ms 23920 KB Output is correct
56 Correct 149 ms 23888 KB Output is correct
57 Correct 59 ms 14080 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 67 ms 14072 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Incorrect 1 ms 212 KB Too many ways to get from 0 to 9, should be 1 found no less than 2
64 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1188 KB Output is correct
7 Correct 147 ms 22020 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 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 6 ms 1108 KB Output is correct
13 Correct 148 ms 22020 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 70 ms 12052 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 37 ms 5736 KB Output is correct
21 Correct 146 ms 22020 KB Output is correct
22 Correct 146 ms 22076 KB Output is correct
23 Correct 151 ms 22032 KB Output is correct
24 Correct 146 ms 22024 KB Output is correct
25 Correct 62 ms 12052 KB Output is correct
26 Correct 59 ms 12048 KB Output is correct
27 Correct 152 ms 21964 KB Output is correct
28 Correct 157 ms 22028 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 296 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 6 ms 1236 KB Output is correct
37 Correct 163 ms 23920 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 6 ms 1240 KB Output is correct
41 Correct 150 ms 23676 KB Output is correct
42 Correct 1 ms 296 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 3 ms 820 KB Output is correct
45 Correct 70 ms 14092 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 38 ms 6184 KB Output is correct
50 Correct 150 ms 23948 KB Output is correct
51 Correct 156 ms 23892 KB Output is correct
52 Correct 149 ms 23888 KB Output is correct
53 Correct 59 ms 14068 KB Output is correct
54 Correct 60 ms 14068 KB Output is correct
55 Correct 179 ms 23920 KB Output is correct
56 Correct 149 ms 23888 KB Output is correct
57 Correct 59 ms 14080 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 36 ms 5708 KB Output is correct
62 Correct 151 ms 22032 KB Output is correct
63 Correct 156 ms 22248 KB Output is correct
64 Correct 150 ms 22000 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 36 ms 5720 KB Output is correct
67 Correct 153 ms 21956 KB Output is correct
68 Correct 156 ms 21984 KB Output is correct
69 Correct 151 ms 21992 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Incorrect 0 ms 212 KB Too many ways to get from 4 to 8, should be 1 found no less than 2
72 Halted 0 ms 0 KB -