結果

問題 No.79 過小評価ダメ・ゼッタイ
ユーザー higesawahigesawa
提出日時 2023-08-04 18:03:55
言語 Ruby
(3.3.0)
結果
AC  
実行時間 121 ms / 5,000 ms
コード長 627 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 19,328 KB
最終ジャッジ日時 2024-04-22 16:06:17
合計ジャッジ時間 4,002 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
12,160 KB
testcase_01 AC 121 ms
19,200 KB
testcase_02 AC 75 ms
12,032 KB
testcase_03 AC 78 ms
12,032 KB
testcase_04 AC 78 ms
11,904 KB
testcase_05 AC 119 ms
19,328 KB
testcase_06 AC 79 ms
12,032 KB
testcase_07 AC 77 ms
11,904 KB
testcase_08 AC 75 ms
12,032 KB
testcase_09 AC 76 ms
11,904 KB
testcase_10 AC 77 ms
12,160 KB
testcase_11 AC 77 ms
12,032 KB
testcase_12 AC 76 ms
11,904 KB
testcase_13 AC 78 ms
12,032 KB
testcase_14 AC 105 ms
16,640 KB
testcase_15 AC 87 ms
13,312 KB
testcase_16 AC 117 ms
18,048 KB
testcase_17 AC 85 ms
12,928 KB
testcase_18 AC 109 ms
18,048 KB
testcase_19 AC 98 ms
15,744 KB
testcase_20 AC 118 ms
19,328 KB
testcase_21 AC 78 ms
12,032 KB
testcase_22 AC 95 ms
14,208 KB
testcase_23 AC 115 ms
18,944 KB
testcase_24 AC 118 ms
19,072 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.chomp.to_i

Ls = gets.chomp.split.map(&:to_i) # => [1, 2, 3, 4, 1,]

counts = Ls.uniq.map{|item| [item, Ls.count(item)]}.to_h # => {1=>2, 2=>1, 3=>1, 4=>1}

# 任意の値が2個以上あるか確認する
values = counts.values # => [2, 1, 1, 1] 値のみを取り出す

# 最も大きい値が配列の中に1つしかない場合、キーを参照しputする
# 最もおきい値が2個以上の場合、あればキーを参照し、キーの数値が大きい方をputする
if values.count(values.max) == 1
  puts counts.key(values.max)
else
  puts counts.select { |k,value| value == values.max }.keys.max
end
0