답안 #300159

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
300159 2020-09-16T21:59:52 Z model_code 슈퍼트리 잇기 (IOI20_supertrees) C++17
46 / 100
254 ms 22256 KB
// limli-always-possible-st4
#include <bits/stdc++.h>

#include "supertrees.h"
using namespace std;

int construct(vector<vector<int>> p) {
    int n = p.size();
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (p[i][j] == 3) return 0;
        }
    }
    vector<vector<int>> answer;
    for (int i = 0; i < n; i++) {
        vector<int> row;
        row.resize(n);
        answer.push_back(row);
    }
    vector<bool> visited(n);
    vector<int> componentIndex(n);
    vector<int> lineIndex(n);
    for (int aa = 0; aa < n; aa++) {
        if (visited[aa]) continue;
        queue<int> qcomponent;
        qcomponent.push(aa);
        vector<int> cycle;
        while (!qcomponent.empty()) {
            int x = qcomponent.front();
            qcomponent.pop();
            if (visited[x]) continue;
            vector<int> curline;
            queue<int> qline;
            qline.push(x);
            cycle.push_back(x);
            while (!qline.empty()) {
                int y = qline.front();
                qline.pop();
                if (visited[y]) continue;
                curline.push_back(y);
                visited[y] = true;
                componentIndex[y] = aa;
                lineIndex[y] = x;
                for (int i = 0; i < n; i++) {
                    if (p[y][i] == 2)
                        qcomponent.push(i);
                    else if (p[y][i] == 1)
                        qline.push(i);
                }
            }
            // for (int i : curline) printf("%d ", i); printf("\n");
            if (curline.size() > 1) {
                for (int i = 0; i < curline.size() - 1; i++) {
                    int a = curline[i];
                    int b = curline[i + 1];
                    answer[a][b] = answer[b][a] = 1;
                }
            }
        }
        if (cycle.size() == 2) return 0;
        if (cycle.size() == 1) continue;
        for (int i = 0; i < cycle.size(); i++) {
            int a = cycle[i];
            int b = cycle[(i + 1) % cycle.size()];
            answer[a][b] = answer[b][a] = 1;
        }
    }
    build(answer);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:53:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |                 for (int i = 0; i < curline.size() - 1; i++) {
      |                                 ~~^~~~~~~~~~~~~~~~~~~~
supertrees.cpp:62:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for (int i = 0; i < cycle.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 10 ms 1244 KB Output is correct
7 Correct 241 ms 22116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 10 ms 1244 KB Output is correct
7 Correct 241 ms 22116 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1152 KB Output is correct
13 Correct 233 ms 22140 KB Output is correct
14 Incorrect 1 ms 384 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 10 ms 1152 KB Output is correct
9 Correct 246 ms 22136 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1244 KB Output is correct
13 Correct 246 ms 22256 KB Output is correct
14 Incorrect 1 ms 256 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 80 ms 5880 KB Output is correct
5 Correct 241 ms 22104 KB Output is correct
6 Correct 237 ms 22104 KB Output is correct
7 Correct 254 ms 22100 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 65 ms 5860 KB Output is correct
10 Correct 247 ms 22136 KB Output is correct
11 Correct 237 ms 22072 KB Output is correct
12 Correct 244 ms 22096 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 59 ms 5752 KB Output is correct
17 Correct 243 ms 22180 KB Output is correct
18 Correct 241 ms 22084 KB Output is correct
19 Correct 246 ms 22104 KB Output is correct
20 Correct 236 ms 22136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 10 ms 1244 KB Output is correct
7 Correct 241 ms 22116 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1152 KB Output is correct
13 Correct 233 ms 22140 KB Output is correct
14 Incorrect 1 ms 384 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 10 ms 1244 KB Output is correct
7 Correct 241 ms 22116 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1152 KB Output is correct
13 Correct 233 ms 22140 KB Output is correct
14 Incorrect 1 ms 384 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -