結果

問題 No.723 2つの数の和
ユーザー YoteichiYoteichi
提出日時 2018-08-04 04:25:07
言語 Ruby
(3.3.0)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 361 bytes
コンパイル時間 60 ms
コンパイル使用メモリ 11,952 KB
実行使用メモリ 38,784 KB
最終ジャッジ日時 2023-10-19 21:43:11
合計ジャッジ時間 4,601 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
16,108 KB
testcase_01 AC 87 ms
16,108 KB
testcase_02 AC 86 ms
16,108 KB
testcase_03 AC 166 ms
25,376 KB
testcase_04 AC 192 ms
31,992 KB
testcase_05 AC 178 ms
26,480 KB
testcase_06 AC 189 ms
27,116 KB
testcase_07 AC 132 ms
23,320 KB
testcase_08 AC 139 ms
24,912 KB
testcase_09 AC 194 ms
32,656 KB
testcase_10 AC 131 ms
22,808 KB
testcase_11 AC 97 ms
17,208 KB
testcase_12 AC 145 ms
25,912 KB
testcase_13 AC 196 ms
32,924 KB
testcase_14 AC 116 ms
19,528 KB
testcase_15 AC 136 ms
24,452 KB
testcase_16 AC 155 ms
27,340 KB
testcase_17 AC 177 ms
26,188 KB
testcase_18 AC 140 ms
23,260 KB
testcase_19 AC 143 ms
23,608 KB
testcase_20 AC 86 ms
16,108 KB
testcase_21 AC 86 ms
16,104 KB
testcase_22 AC 87 ms
16,108 KB
testcase_23 AC 229 ms
38,784 KB
testcase_24 AC 120 ms
21,372 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|
    if hx && hx == k
        next
    end
    count += table[k] * (table[x - k] || 0)
end
puts count
0