提出 #3296591


ソースコード 拡げる

N, *VS = $stdin.read.split.map(&:to_i)
occ = [{}, {}]
for i in 0...(N/2)
  occ[0][VS[i*2  ]] = (occ[0][VS[i*2  ]] || 0) + 1
  occ[1][VS[i*2+1]] = (occ[1][VS[i*2+1]] || 0) + 1
end
ranking = [
  occ[0].sort_by(&:last),
  occ[1].sort_by(&:last),
]
def ans(na, nb); p (N/2 - na) + (N/2 - nb); end
a1, na1 = *ranking[0][-1]
b1, nb1 = *ranking[1][-1]
a2, na2 = *ranking[0][-2]
b2, nb2 = *ranking[1][-2]
if a1 != b1
  ans(na1, nb1)
else
  if na1 < nb1
    ans(na2, nb1)
  elsif na1 > nb1
    ans(na1, nb2)
  else # 1位が同数
    if na2.nil?  # 全部同じ数
      p N/2
    else
      ans(na1, [na2, nb2].max)
    end
  end
end

提出情報

提出日時
問題 C - /\/\/\/
ユーザ yhara
言語 Ruby (2.3.3)
得点 300
コード長 657 Byte
結果 AC
実行時間 145 ms
メモリ 21224 KiB

コンパイルエラー

./Main.rb:14: warning: assigned but unused variable - a2
./Main.rb:15: warning: assigned but unused variable - b2

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 3
AC × 20
セット名 テストケース
Sample sample1_3132.txt, sample2_iw.txt, sample3_1111.txt
All ababa_0.txt, ababa_1.txt, eq_0.txt, eq_1.txt, rnd_17.txt, sample1_3132.txt, sample2_iw.txt, sample3_1111.txt, top2_0.txt, top2_1.txt, top2_2.txt, top2_3.txt, top2modoki_0.txt, top2modoki_1.txt, top2modoki_2.txt, top2modoki_3.txt, vary_1.txt, vary_2.txt, vary_3.txt, zoro_0.txt
ケース名 結果 実行時間 メモリ
ababa_0.txt AC 103 ms 15608 KiB
ababa_1.txt AC 103 ms 15608 KiB
eq_0.txt AC 67 ms 8828 KiB
eq_1.txt AC 67 ms 8828 KiB
rnd_17.txt AC 67 ms 8828 KiB
sample1_3132.txt AC 7 ms 1788 KiB
sample2_iw.txt AC 7 ms 1788 KiB
sample3_1111.txt AC 7 ms 1788 KiB
top2_0.txt AC 75 ms 9720 KiB
top2_1.txt AC 74 ms 9720 KiB
top2_2.txt AC 75 ms 9720 KiB
top2_3.txt AC 74 ms 9720 KiB
top2modoki_0.txt AC 75 ms 9848 KiB
top2modoki_1.txt AC 75 ms 9720 KiB
top2modoki_2.txt AC 75 ms 9848 KiB
top2modoki_3.txt AC 76 ms 9720 KiB
vary_1.txt AC 145 ms 21224 KiB
vary_2.txt AC 141 ms 21104 KiB
vary_3.txt AC 126 ms 17136 KiB
zoro_0.txt AC 7 ms 1788 KiB