답안 #766961

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
766961 2023-06-26T09:38:15 Z simene 자동 인형 (IOI18_doll) C++14
컴파일 오류
0 ms 0 KB
#include "doll.h"
#include <vector>
#include <bits/stdc++.h>

class Node 
{
public:
    Node* left;
    Node* right;
    Node* parent;
    bool state = false;
    int ltrig = -1;
    int rtrig = -1;
    int id = -1;

    void construct(int lvls) 
    {
        if (lvls <= 0) return;

        left = new Node();
        right = new Node();

        left->parent = this;
        right->parent = this;

        left->construct(lvls - 1);
        right->construct(lvls - 1);
    }

    Node* traverse() 
    {
        if (left == nullptr) return this;

        if (state) 
        {
            state = !state;
            return right;
        }
        else 
        {
            state = !state;
            return left;
        }
    }

    void insert(int trig) 
    {
        Node* ins = traverse();

        ins->state = !ins->state;

        if (ins->state) ins->ltrig = trig;
        else ins->right = trig;
    }

    int prune() 
    {
        int s = 1;

        if (right != nullptr) s += right->prune;
        if (left != nullptr) s += left->prune;

        if (right == nullptr && rtrig == -1) 
        {
            if (left != nullptr) 
            {
                if (parent->left == this) parent->left = left;
                else parent->right = left;
            }
            else if (ltrig != -1) 
            {
                if (parent->left == this) parent->ltrig = ltrig;
                else parent->rtrig = ltrig;
            }
            else 
            {
                if (parent->left == this) parent->left = nullptr;
                else parent->left = nullptr;

                return 0;
            }
        }

        return s;
    }

    int identify(int nextid, int* X[], int* Y[])
    {
        id = nextid--;

        if (left != nullptr) nextid = left->identify(nextid, X, Y);
        if (right != nullptr) nextid = right->identify(nextid, X, Y);

        if (left != nullptr) X[-id - 1] = left->id;
        else X[-id - 1] = ltrig;

        if (right != nullptr) Y[-id - 1] = right->id;
        else Y[-id - 1] = rtrig;

        return nextid;
    }
};

void create_circuit(int M, std::vector<int> A) 
{
    Node* root;

    A.push_back(0);

    int N = A.size();

    int height = (int)ceil(log2(N));

    root->construct(height);

    for (int i : A) 
    {
        root->insert(i);
    }

    int s = root->prune;

    int C[M + 1];
    for (int i = 0; i < M + 1; i++) C[i] = -1;

    int X[s];
    int Y[s];

    root->identify(-1, &X, &Y);

    answer(C, X, Y);
}

Compilation message

doll.cpp: In member function 'void Node::insert(int)':
doll.cpp:53:27: error: invalid conversion from 'int' to 'Node*' [-fpermissive]
   53 |         else ins->right = trig;
      |                           ^~~~
      |                           |
      |                           int
doll.cpp: In member function 'int Node::prune()':
doll.cpp:60:43: error: invalid use of member function 'int Node::prune()' (did you forget the '()' ?)
   60 |         if (right != nullptr) s += right->prune;
      |                                    ~~~~~~~^~~~~
      |                                                ()
doll.cpp:61:41: error: invalid use of member function 'int Node::prune()' (did you forget the '()' ?)
   61 |         if (left != nullptr) s += left->prune;
      |                                   ~~~~~~^~~~~
      |                                              ()
doll.cpp: In member function 'int Node::identify(int, int**, int**)':
doll.cpp:94:49: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   94 |         if (left != nullptr) X[-id - 1] = left->id;
      |                                           ~~~~~~^~
      |                                                 |
      |                                                 int
doll.cpp:95:27: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   95 |         else X[-id - 1] = ltrig;
      |                           ^~~~~
      |                           |
      |                           int
doll.cpp:97:51: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   97 |         if (right != nullptr) Y[-id - 1] = right->id;
      |                                            ~~~~~~~^~
      |                                                   |
      |                                                   int
doll.cpp:98:27: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   98 |         else Y[-id - 1] = rtrig;
      |                           ^~~~~
      |                           |
      |                           int
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:121:19: error: cannot convert 'Node::prune' from type 'int (Node::)()' to type 'int'
  121 |     int s = root->prune;
      |                   ^~~~~
doll.cpp:129:24: error: cannot convert 'int (*)[s]' to 'int**'
  129 |     root->identify(-1, &X, &Y);
      |                        ^~
      |                        |
      |                        int (*)[s]
doll.cpp:87:35: note:   initializing argument 2 of 'int Node::identify(int, int**, int**)'
   87 |     int identify(int nextid, int* X[], int* Y[])
      |                              ~~~~~^~~
doll.cpp:131:12: error: could not convert '(int*)(& C)' from 'int*' to 'std::vector<int>'
  131 |     answer(C, X, Y);
      |            ^
      |            |
      |            int*