結果

問題 No.241 出席番号(1)
ユーザー hytkxd
提出日時 2024-05-08 00:29:09
言語 Ruby
(3.4.1)
結果
RE  
実行時間 -
コード長 1,364 bytes
コンパイル時間 480 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-11-30 21:47:07
合計ジャッジ時間 6,125 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 RE * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:39: warning: assigned but unused variable - numarr
Main.rb:53: warning: assigned but unused variable - r
Syntax OK

ソースコード

diff #

#!/usr/local/bin/ruby
class BipartiteMatching
  def initialize(n,adj)
    @n,@adj = n,adj # adj is already satisfied with bipartite property.
  end
  private
  def dfs(v)
    rop = false
    @visited[v] = true
    @adj[v].each do |u|
      w = @match[u]
      if w.nil? || (@visited[w].nil? && dfs(w))
        rop,@match[v],@match[u] = true,u,v
        break
      end
    end
    rop
  end
  public
  def matching
    #kuhn algorithm:
    # Start by unsaturated vertex, find an augmenting path, update the matching.
    r = 0
    @match = Array.new(@n)
    (0...@n).each do |i|
      unless @match[i]
        @visited = Array.new(@n)
        if dfs(i)
          r+=1
        end
      end
    end
    [r,@match]
  end
end
class StudentNumber
  def initialize(*arg)
    @n,@a, = arg
    numarr = (@n...2*@n).to_a
    @adj = Array.new(2*@n){Array.new}
    (0...@n).each do |i|
      (0...@a[i]).each do |j|
        @adj[i].push(@n+j)
        @adj[@n+j].push(i)
      end
      (@a[i]+1...@n).each do |j|
        @adj[i].push(@n+j)
        @adj[@n+j].push(i)
      end
    end
  end
  def ans
    r,marr = BipartiteMatching.new(2*@n,@adj).matching
    if marr.any?(nil)
      [-1]
    else
      marr[0,@n].map{_1-@n}
    end
  end
end
### END: class StudentNumber
iod = STDIN
n = iod.gets.to_i
a = Array.new(n){iod.gets.to_i}
puts StudentNumber.new(n,a).ans
exit 0
0