結果

問題 No.2126 MEX Game
ユーザー simansiman
提出日時 2022-11-20 07:39:03
言語 Ruby
(3.3.0)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 434 bytes
コンパイル時間 51 ms
コンパイル使用メモリ 11,908 KB
実行使用メモリ 35,948 KB
最終ジャッジ日時 2023-10-21 08:36:53
合計ジャッジ時間 4,861 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
16,092 KB
testcase_01 AC 87 ms
16,092 KB
testcase_02 AC 86 ms
16,092 KB
testcase_03 AC 85 ms
16,092 KB
testcase_04 AC 86 ms
16,092 KB
testcase_05 AC 86 ms
16,092 KB
testcase_06 AC 86 ms
16,092 KB
testcase_07 AC 86 ms
16,092 KB
testcase_08 AC 87 ms
16,092 KB
testcase_09 AC 86 ms
16,092 KB
testcase_10 AC 169 ms
28,148 KB
testcase_11 AC 187 ms
28,148 KB
testcase_12 AC 178 ms
29,760 KB
testcase_13 AC 178 ms
29,760 KB
testcase_14 AC 175 ms
30,264 KB
testcase_15 AC 176 ms
30,796 KB
testcase_16 AC 176 ms
30,096 KB
testcase_17 AC 158 ms
23,708 KB
testcase_18 AC 162 ms
24,032 KB
testcase_19 AC 146 ms
23,604 KB
testcase_20 AC 144 ms
23,604 KB
testcase_21 AC 186 ms
35,948 KB
testcase_22 AC 85 ms
16,092 KB
testcase_23 AC 84 ms
16,092 KB
testcase_24 AC 84 ms
16,092 KB
testcase_25 AC 84 ms
16,092 KB
testcase_26 AC 88 ms
16,092 KB
testcase_27 AC 85 ms
16,092 KB
testcase_28 AC 85 ms
16,092 KB
testcase_29 AC 86 ms
16,092 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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