結果

問題 No.1988 Divisor Tiling
ユーザー mai
提出日時 2022-06-24 23:22:07
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 645 bytes
コンパイル時間 117 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-11-08 18:57:50
合計ジャッジ時間 8,060 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 16 WA * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:46: 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

div.each do |w|
  h2 = 0
  stk = 0
  ok = true
  div.each do |x|
    if x/w*w != x
      stk += x
      if stk > w
        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
    
    stk = []
    div.each do |x|
      if x/w*w != x
        stk += [x]*x
        if stk.size == w
          puts stk*' '
          stk = []
        end
        next
      end
      (x/w).times {puts [x]*w*' '}
    end
    exit
  end
end

p -1
0