結果

問題 No.2126 MEX Game
ユーザー siman
提出日時 2022-11-20 07:39:03
言語 Ruby
(3.4.1)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 434 bytes
コンパイル時間 43 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 32,256 KB
最終ジャッジ日時 2024-09-21 09:40:51
合計ジャッジ時間 4,477 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:6: warning: assigned but unused variable - ans
Syntax OK

ソースコード

diff #

N = gets.to_i
A = gets.split.map(&:to_i).sort
C = A.tally
C.default = 0

ans = 0

def f(nums)
  c = nums.tally
  c.default = 0
  m = nums.max

  0.upto(m) do |x|
    return [false, x] if c[x] <= 1
  end

  [true, m + 1]
end

res, v = f(A)

if res
  puts v
else
  idx = A.rindex { |a| a > v }
  idx = A.index { |a| a < v && C[a] >= 3 } if idx.nil?

  if idx.nil?
    puts v
  else
    A[idx] = v

    _, v = f(A)

    puts v
  end
end
0