結果

問題 No.1988 Divisor Tiling
ユーザー simansiman
提出日時 2022-06-30 16:20:56
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 783 bytes
コンパイル時間 252 ms
コンパイル使用メモリ 11,392 KB
実行使用メモリ 16,252 KB
最終ジャッジ日時 2023-08-16 03:17:01
合計ジャッジ時間 7,894 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
15,360 KB
testcase_01 WA -
testcase_02 AC 93 ms
15,352 KB
testcase_03 AC 92 ms
15,436 KB
testcase_04 AC 93 ms
15,632 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 94 ms
15,420 KB
testcase_08 AC 91 ms
15,516 KB
testcase_09 AC 94 ms
15,448 KB
testcase_10 AC 95 ms
15,556 KB
testcase_11 AC 94 ms
15,396 KB
testcase_12 AC 94 ms
15,444 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 93 ms
15,172 KB
testcase_18 AC 97 ms
15,580 KB
testcase_19 AC 97 ms
15,708 KB
testcase_20 AC 95 ms
15,680 KB
testcase_21 AC 96 ms
15,400 KB
testcase_22 AC 97 ms
15,496 KB
testcase_23 AC 97 ms
15,588 KB
testcase_24 AC 97 ms
15,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 108 ms
16,252 KB
testcase_32 AC 93 ms
15,360 KB
testcase_33 AC 93 ms
15,212 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:18: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

class Integer
  def divisor_list
    require 'prime'

    return [] if self <= 0
    return [1] if self == 1

    prime_division.map.with_index { |(base, k), i|
      s = i.zero? ? 0 : 1
      (s..k).map { |n| base ** n }
    }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort
  end
end

N, H = gets.split.map(&:to_i)

if N % H != 0
  puts -1
  exit
end

W = N / H
ans = Array.new(H) { Array.new(N / H, 0) }
y = 0
x = 0

N.divisor_list.reverse_each do |v|
  next if v == N
  h = v / W
  w = v % W

  if h > 0
    y.upto(y + h - 1) do |cy|
      0.upto(W - 1) do |cx|
        ans[cy][cx] = v
      end
    end
  else
    w.times do
      ans[y][x] = v
      x += 1
    end
  end

  if h > 0
    y += h
    x = 0
  end
end

puts ans.map { |row| row.join(' ') }

0