結果

問題 No.241 出席番号(1)
ユーザー siman
提出日時 2021-10-18 17:06:04
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 366 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-09-19 12:23:21
合計ジャッジ時間 4,030 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 27 WA * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:24: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

N = gets.to_i
A = N.times.map { gets.to_i }
counter = Hash.new(0)

A.each do |a|
  counter[a] += 1
end

nums = [*0...N].sort_by { |i| -counter[i] }
ans = Array.new(N, -1)

nums.each do |n|
  ok = false
  N.times do |i|
    next if ans[i] != -1
    next if A[i] == n

    ok = true
    ans[i] = n
    break
  end

  if not ok
    puts -1
    exit
  end
end

puts ans
0