forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathceiling.cpp
78 lines (67 loc) · 1.46 KB
/
ceiling.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <unordered_map>
#include <iostream>
using namespace std;
struct node {
int n;
node* left = nullptr;
node* right = nullptr;
};
string traverse(node* root, int level) {
// Base case
if(root == nullptr) {
return "";
}
// Build string
string ans;
ans += traverse(root->left, level+1);
ans += char(level);
ans += traverse(root->right, level+1);
return ans;
}
void insert(node* root, int n) {
if(root->n < n) {
if(root->right == nullptr) {
node* temp = new node;
temp->n = n;
root->right = temp;
}
else {
insert(root->right, n);
}
}
if(root->n > n) {
if(root->left == nullptr) {
node* temp = new node;
temp->n = n;
root->left = temp;
}
else {
insert(root->left, n);
}
}
}
int main() {
int trees, nodes;
cin >> trees >> nodes;
unordered_map<string, int> designs;
// Create trees
for(int i = 0; i < trees; i++) {
node* n = new node;
n->n = -1;
for(int j = 0; j < nodes; j++) {
int temp;
cin >> temp;
insert(n, temp);
}
string s = traverse(n, 0);
//cout << s << endl;
designs[s]++;
}
// Count the unique designs
int total = 0;
for(auto i : designs) {
total++;
}
// Print the answer
cout << total << endl;
}