結果

問題 No.1988 Divisor Tiling
ユーザー maimai
提出日時 2022-06-24 23:31:41
言語 Ruby
(3.2.2)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 757 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 11,576 KB
実行使用メモリ 16,304 KB
最終ジャッジ日時 2023-08-08 13:25:03
合計ジャッジ時間 5,076 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,136 KB
testcase_01 AC 78 ms
15,092 KB
testcase_02 AC 77 ms
15,284 KB
testcase_03 AC 78 ms
15,092 KB
testcase_04 AC 77 ms
15,160 KB
testcase_05 AC 78 ms
15,340 KB
testcase_06 AC 78 ms
15,052 KB
testcase_07 AC 78 ms
15,136 KB
testcase_08 AC 79 ms
15,032 KB
testcase_09 AC 78 ms
15,164 KB
testcase_10 AC 77 ms
15,088 KB
testcase_11 AC 78 ms
15,044 KB
testcase_12 AC 77 ms
15,340 KB
testcase_13 AC 78 ms
15,296 KB
testcase_14 AC 78 ms
15,292 KB
testcase_15 AC 77 ms
15,084 KB
testcase_16 AC 80 ms
15,132 KB
testcase_17 AC 78 ms
15,036 KB
testcase_18 AC 86 ms
15,796 KB
testcase_19 AC 84 ms
15,416 KB
testcase_20 AC 81 ms
15,124 KB
testcase_21 AC 81 ms
15,372 KB
testcase_22 AC 82 ms
15,492 KB
testcase_23 AC 82 ms
15,228 KB
testcase_24 AC 84 ms
15,168 KB
testcase_25 AC 85 ms
15,536 KB
testcase_26 AC 86 ms
15,620 KB
testcase_27 AC 83 ms
15,348 KB
testcase_28 AC 84 ms
15,232 KB
testcase_29 AC 82 ms
15,512 KB
testcase_30 AC 85 ms
15,596 KB
testcase_31 AC 94 ms
16,304 KB
testcase_32 AC 77 ms
15,140 KB
testcase_33 AC 78 ms
15,136 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:51: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

def lscan; gets.split.map(&:to_i); end

n, h = lscan

div = (1..(n-1)).filter{|x| n/x*x == n}.to_a

dd = div + [n]

dd.each do |w|
  h2 = 0
  stk = 0
  ok = true
  div.each do |x|
    if x/w*w != x
      stk += x
      if stk > w
        # p [w, stk]
        ok = false
        break
      end
      if stk == w
        h2 += 1
        stk = 0
      end
      next
    end
    h2 += x/w
  end
  next unless ok
  # p h2
  if h2 == h || w == h
    mat = []
    stk = []
    div.each do |x|
      if x/w*w != x
        stk += [x]*x
        if stk.size == w
          mat << stk
          stk = []
        end
        next
      end
      (x/w).times {mat << [x]*w}
    end
    mat = mat.transpose if w == h
    puts mat.map{|l| l*' '}
    exit
  end
end

p -1
0