結果
問題 | No.241 出席番号(1) |
ユーザー |
|
提出日時 | 2024-05-08 00:37:06 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 98 ms / 2,000 ms |
コード長 | 1,351 bytes |
コンパイル時間 | 230 ms |
コンパイル使用メモリ | 7,168 KB |
実行使用メモリ | 12,288 KB |
最終ジャッジ日時 | 2024-11-30 21:55:08 |
合計ジャッジ時間 | 4,403 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
コンパイルメッセージ
Main.rb:52: warning: assigned but unused variable - r Syntax OK
ソースコード
#!/usr/local/bin/rubyclass BipartiteMatchingdef initialize(n,adj)@n,@adj = n,adj # adj is already satisfied with bipartite property.endprivatedef 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,vbreakendendropendpublicdef 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+=1endendend[r,@match]endendclass StudentNumberdef initialize(*arg)@n,@a, = arg@adj = Array.new(2*@n){Array.new}(0...@n).each do |i|(0...[@a[i],@n].min).each do |j|@adj[i].push(@n+j)@adj[@n+j].push(i)end([0,@a[i]+1].max...@n).each do |j|@adj[i].push(@n+j)@adj[@n+j].push(i)endendenddef ansr,marr = BipartiteMatching.new(2*@n,@adj).matchingif marr.any?(nil)[-1]elsemarr[0,@n].map{_1-@n}endendend### END: class StudentNumberiod = STDINn = iod.gets.to_ia = Array.new(n){iod.gets.to_i}puts StudentNumber.new(n,a).ansexit 0