-
Notifications
You must be signed in to change notification settings - Fork 185
/
ceiling.odin
59 lines (53 loc) · 985 Bytes
/
ceiling.odin
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
// https://open.kattis.com/problems/ceiling
package main
import "core:c/libc"
import "core:fmt"
import "core:slice"
Node :: struct {
v: int,
l: ^Node,
r: ^Node,
}
N :: 50
trees : [N]^Node
hashes : [N][dynamic]u8
insert :: proc(n: ^Node, v: int) -> ^Node {
if n == nil {
node := new(Node)
node.v = v
return node
}
if v < n.v do n.l = insert(n.l, v)
else do n.r = insert(n.r, v)
return n
}
traverse :: proc(n: ^Node, h: ^[dynamic]u8) {
h := h
if n.l != nil {
append(h, 'l')
traverse(n.l, h)
}
if n.r != nil {
append(h, 'r')
traverse(n.r, h)
}
append(h, 'u')
}
main :: proc() {
n, k : int
libc.scanf("%d %d", &n, &k)
for i in 0..<n {
for j in 0..<k {
x : int
libc.scanf("%d", &x)
trees[i] = insert(trees[i], x)
}
traverse(trees[i], &hashes[i])
}
strings := make([]string, n)
for i in 0..<n do strings[i] = string(hashes[i][:])
slice.sort(strings)
c := 1
for i in 1..<n do if strings[i-1] != strings[i] do c += 1
fmt.println(c)
}