結果

問題 No.1851 Regular Tiling
ユーザー simansiman
提出日時 2022-03-11 04:23:55
言語 Ruby
(3.3.0)
結果
AC  
実行時間 582 ms / 2,000 ms
コード長 608 bytes
コンパイル時間 65 ms
コンパイル使用メモリ 11,288 KB
実行使用メモリ 16,600 KB
最終ジャッジ日時 2023-10-13 07:06:12
合計ジャッジ時間 5,971 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,136 KB
testcase_01 AC 203 ms
15,860 KB
testcase_02 AC 236 ms
15,976 KB
testcase_03 AC 221 ms
15,944 KB
testcase_04 AC 214 ms
15,696 KB
testcase_05 AC 216 ms
15,916 KB
testcase_06 AC 235 ms
15,960 KB
testcase_07 AC 209 ms
15,948 KB
testcase_08 AC 212 ms
15,776 KB
testcase_09 AC 234 ms
15,804 KB
testcase_10 AC 219 ms
15,644 KB
testcase_11 AC 84 ms
15,140 KB
testcase_12 AC 86 ms
15,252 KB
testcase_13 AC 341 ms
16,600 KB
testcase_14 AC 582 ms
15,992 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

B = [
  [0, 1, 1],
  [1, 2, 2],
  [1, 2, 2],
]

T = gets.to_i

def build_grid(h, w)
  grid = []
  ly = Rational(h, 3).ceil
  lx = Rational(w, 3).ceil

  (ly * 3).times do |y|
    row = []
    (lx * 3).times do |x|
      row << B[y % 3][x % 3]
    end

    grid << row
  end

  if h % 3 == 1
    grid.pop(2)
  elsif h % 3 == 2
    grid.shift
  end

  if w % 3 == 1
    grid = grid.map { |row| row.pop(2); row }
  elsif w % 3 == 2
    grid = grid.map { |row| row.shift; row }
  end

  grid
end

T.times do
  h, w = gets.split.map(&:to_i)

  grid = build_grid(h, w)

  puts grid.map { |row| row.join(' ') }
end
0