Submission #1099105

# Submission time Handle Problem Language Result Execution time Memory
1099105 2024-10-10T14:44:00 Z vjudge1 Rack (eJOI19_rack) C++17
40 / 100
84 ms 102400 KB
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

struct Node
{
    int value;
    Node* right;
    Node* left;

    Node(int val) : value(val), left(nullptr), right(nullptr) {}
};

class Tree
{
    public:
    Node* root;

    Tree(int height) {
        root = nullptr;
        int leafValue = 0;
        build(root, height, leafValue);
    }

    void build(Node*& node, int height, int& leafValue) {
        if(height == 0) return;
        node = new Node(0);

        build(node -> left, height -1, leafValue);
        build(node -> right, height -1, leafValue);
    
        if (height == 1) { leafValue++; node -> value = leafValue; }
    }

    int traverse(vector<int> path, int height) {
        Node* current = root;
        for (int i = 0; i < height; ++i) {
            current = (path[i] == 0) ? current->left : current->right;
        }

        return current ? current -> value : -1;
    }
};


int main()
{
    int height, node;
    cin >> height >> node;
    int rows = 1 << height;

    Tree tree(height + 1);


    std::vector<int> path(height);
    for (int i = 0; i < node; ++i) {
        for (int j = 0; j < height; ++j) path[j] = (i >> j) & 1;
    }

    cout << tree.traverse(path, height) << endl;
    return 0;
}

Compilation message

rack.cpp: In constructor 'Node::Node(int)':
rack.cpp:12:11: warning: 'Node::left' will be initialized after [-Wreorder]
   12 |     Node* left;
      |           ^~~~
rack.cpp:11:11: warning:   'Node* Node::right' [-Wreorder]
   11 |     Node* right;
      |           ^~~~~
rack.cpp:14:5: warning:   when initialized here [-Wreorder]
   14 |     Node(int val) : value(val), left(nullptr), right(nullptr) {}
      |     ^~~~
rack.cpp: In function 'int main()':
rack.cpp:53:9: warning: unused variable 'rows' [-Wunused-variable]
   53 |     int rows = 1 << height;
      |         ^~~~
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 4 ms 4444 KB Output is correct
9 Correct 15 ms 16624 KB Output is correct
10 Correct 53 ms 65876 KB Output is correct
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 4 ms 4444 KB Output is correct
9 Correct 15 ms 16624 KB Output is correct
10 Correct 53 ms 65876 KB Output is correct
11 Runtime error 84 ms 102400 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -