Submission #1400886
Source Code Expand
# http://rco-contest-2017-qual.contest.atcoder.jp/tasks/rco_contest_2017_qual_a
class PieceCalculator
def initialize(h, w, k, ary)
@did_pieces = []
@H = h
@W = w
@K = k
@ary = ary
end
# pieceを作成する
def create_piece
start = get_start_point
piece = [start]
@did_pieces << start
(0...7).each{
neighbors = find_neighbors(piece)
if neighbors.length == 0
return nil
end
selected = neighbors.first
neighbors.each{ |v|
i, j = v[0], v[1]
i_now, j_now = selected[0], selected[1]
if @ary[i][j] > @ary[i_now][j_now]
selected = [i, j]
end
}
piece << selected
@did_pieces << selected
}
piece
end
def get_start_point
i, j = rand(@H), rand(@W)
while @ary[i][j] == 0 || (@did_pieces != [] && @did_pieces.include?([i, j]))
i, j = rand(@H), rand(@W)
end
[i, j]
end
# ピース隣接するマスを返す
def find_neighbors(piece)
neighbors = []
piece.each{ |ary|
i, j = ary[0], ary[1]
neighbors << [i+1, j] if i+1 < 50 && @ary[i+1, j] != 0
neighbors << [i-1, j] if 0 <= i-1 && @ary[i-1, j] != 0
neighbors << [i, j+1] if j+1 < 50 && @ary[i, j+1] != 0
neighbors << [i, j-1] if 0 <= j-1 && @ary[i, j-1] != 0
}
piece.each{ |ary|
neighbers = neighbors - ary
}
neighbors - @did_pieces
end
end
# ピースの出力
def print_pieces(pieces)
puts pieces.length
pieces.each{ |piece|
piece.each{ |ary|
puts "#{ary[0]+1} #{ary[1]+1}"
}
}
end
H, W, K = gets.split(" ").map(&:to_i)
ary = []
(0...H).each{
ary << gets.split("").map(&:to_i)
}
pc = PieceCalculator.new(H, W, K, ary)
pieces = []
piece = pc.create_piece
while !piece.nil?
pieces << piece
piece = pc.create_piece
end
print_pieces(pieces)
Submission Info
Submission Time |
|
Task |
A - Multiple Pieces |
User |
mitsu9 |
Language |
Ruby (2.3.3) |
Score |
407374 |
Code Size |
1944 Byte |
Status |
AC |
Exec Time |
1193 ms |
Memory |
2556 KB |
Compile Error
./Main.rb:56: warning: assigned but unused variable - neighbers
Judge Result
Set Name |
test_01 |
test_02 |
test_03 |
test_04 |
test_05 |
test_06 |
test_07 |
test_08 |
test_09 |
test_10 |
Score / Max Score |
49563 / 1343058 |
42474 / 1343058 |
48188 / 1343058 |
35954 / 1343058 |
29451 / 1343058 |
41417 / 1343058 |
45704 / 1343058 |
35707 / 1343058 |
35843 / 1343058 |
43073 / 1343058 |
Status |
|
|
|
|
|
|
|
|
|
|
Set Name |
Test Cases |
test_01 |
subtask_01_01.txt |
test_02 |
subtask_01_02.txt |
test_03 |
subtask_01_03.txt |
test_04 |
subtask_01_04.txt |
test_05 |
subtask_01_05.txt |
test_06 |
subtask_01_06.txt |
test_07 |
subtask_01_07.txt |
test_08 |
subtask_01_08.txt |
test_09 |
subtask_01_09.txt |
test_10 |
subtask_01_10.txt |
Case Name |
Status |
Exec Time |
Memory |
subtask_01_01.txt |
AC |
1025 ms |
2556 KB |
subtask_01_02.txt |
AC |
1193 ms |
2556 KB |
subtask_01_03.txt |
AC |
924 ms |
2556 KB |
subtask_01_04.txt |
AC |
809 ms |
2556 KB |
subtask_01_05.txt |
AC |
168 ms |
1916 KB |
subtask_01_06.txt |
AC |
726 ms |
2556 KB |
subtask_01_07.txt |
AC |
956 ms |
2556 KB |
subtask_01_08.txt |
AC |
462 ms |
2300 KB |
subtask_01_09.txt |
AC |
465 ms |
2300 KB |
subtask_01_10.txt |
AC |
349 ms |
2044 KB |