Submission #1140723
Source Code Expand
def find_pieceX(field, sx, sy) piece = [[sx, sy]] field[sy][sx] = '0' 2.upto(K) do best_n = 0 best_x = best_y = nil piece.each do |x, y| [[0,1],[1,0],[-1,0],[0,1]].each do |dx, dy| nx = x + dx ny = y + dy next if nx < 0 || nx >= W || ny < 0 || ny >= W n = field[ny][nx].to_i next if n <= 0 if n > best_n best_n = n best_x = nx best_y = ny end end end return nil unless best_x piece << [best_x, best_y] field[best_y][best_x] = '0' end piece end def find_piece(field) piece = [] 9.downto(1) do |n| H.times do |y| W.times do |x| if field[y][x].to_i == n ret = find_pieceX(field, x, y) return ret if ret end end end end nil end def solve(field) pieces = [] while piece = find_piece(field) pieces << piece end puts pieces.size pieces.each do |piece| piece.each{|x,y| puts [y+1, x+1]*" "} end end H, W, K = gets.split.map(&:to_i) field = H.times.map{ gets.chomp } solve(field)
Submission Info
Submission Time | |
---|---|
Task | A - Multiple Pieces |
User | yowa |
Language | Ruby (2.3.3) |
Score | 648639 |
Code Size | 1156 Byte |
Status | AC |
Exec Time | 225 ms |
Memory | 2300 KB |
Compile Error
./Main.rb:29: warning: assigned but unused variable - piece ./Main.rb:51: warning: shadowing outer local variable - piece
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 | 63856 / 1343058 | 57249 / 1343058 | 66072 / 1343058 | 62725 / 1343058 | 72269 / 1343058 | 62902 / 1343058 | 72250 / 1343058 | 55217 / 1343058 | 67187 / 1343058 | 68912 / 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 | 183 ms | 2300 KB |
subtask_01_02.txt | AC | 190 ms | 2300 KB |
subtask_01_03.txt | AC | 190 ms | 2300 KB |
subtask_01_04.txt | AC | 220 ms | 2300 KB |
subtask_01_05.txt | AC | 225 ms | 2300 KB |
subtask_01_06.txt | AC | 195 ms | 2300 KB |
subtask_01_07.txt | AC | 205 ms | 2300 KB |
subtask_01_08.txt | AC | 204 ms | 2300 KB |
subtask_01_09.txt | AC | 200 ms | 2300 KB |
subtask_01_10.txt | AC | 208 ms | 2300 KB |