blob: dd4ba41f23ddee7021955171802c180e2a37bf2d (
plain)
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
|
require 'set'
grid = Hash.new
$stdin.readlines.each do |line|
x, y, z = line.strip.split(?,).map(&:to_i)
grid[x] = Hash.new if grid[x].nil?
grid[x][y] = Set.new if grid[x][y].nil?
grid[x][y] << z
end
sa = 0
grid.each do |x, yzs|
yzs.each do |y, zs|
zs.each do |z|
tsa = 6
tsa -= 1 if !grid[x-1].nil? && grid[x-1][y]&.include?(z)
tsa -= 1 if !grid[x+1].nil? && grid[x+1][y]&.include?(z)
tsa -= 1 if grid[x][y-1]&.include?(z)
tsa -= 1 if grid[x][y+1]&.include?(z)
tsa -= 1 if grid[x][y].include?(z-1)
tsa -= 1 if grid[x][y].include?(z+1)
sa += tsa
end
end
end
puts sa
|