結果

問題 No.723 2つの数の和
ユーザー YoteichiYoteichi
提出日時 2018-08-04 04:26:01
言語 Ruby
(3.3.0)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 339 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 38,780 KB
最終ジャッジ日時 2023-10-19 21:43:24
合計ジャッジ時間 5,273 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
16,104 KB
testcase_01 AC 93 ms
16,104 KB
testcase_02 AC 95 ms
16,104 KB
testcase_03 AC 174 ms
25,372 KB
testcase_04 AC 206 ms
31,988 KB
testcase_05 AC 185 ms
26,476 KB
testcase_06 AC 201 ms
27,104 KB
testcase_07 AC 141 ms
23,316 KB
testcase_08 AC 154 ms
24,908 KB
testcase_09 AC 210 ms
32,652 KB
testcase_10 AC 142 ms
22,804 KB
testcase_11 AC 100 ms
17,204 KB
testcase_12 AC 154 ms
25,908 KB
testcase_13 AC 211 ms
32,920 KB
testcase_14 AC 123 ms
19,520 KB
testcase_15 AC 140 ms
24,448 KB
testcase_16 AC 164 ms
27,336 KB
testcase_17 AC 182 ms
26,184 KB
testcase_18 AC 145 ms
23,256 KB
testcase_19 AC 151 ms
23,604 KB
testcase_20 AC 98 ms
16,104 KB
testcase_21 AC 99 ms
16,104 KB
testcase_22 AC 97 ms
16,104 KB
testcase_23 AC 251 ms
38,780 KB
testcase_24 AC 126 ms
21,368 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:1: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

n, x = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
table = a.group_by(&:itself).map { |k,v| [k,v.size] }.to_h
count = 0
hx = table[x.fdiv(2)]
if hx
    if hx == 1
        count += 1
    else
        count += hx**2 - hx
    end
end
table.keys.each do |k|
    next if hx == k
    count += table[k] * (table[x - k] || 0)
end
puts count
0