結果

問題 No.723 2つの数の和
ユーザー YoteichiYoteichi
提出日時 2018-08-04 04:20:13
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 435 bytes
コンパイル時間 51 ms
コンパイル使用メモリ 11,940 KB
実行使用メモリ 38,800 KB
最終ジャッジ日時 2023-10-19 21:43:01
合計ジャッジ時間 4,963 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 91 ms
16,120 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 213 ms
32,940 KB
testcase_14 AC 118 ms
19,540 KB
testcase_15 AC 141 ms
24,468 KB
testcase_16 AC 163 ms
27,352 KB
testcase_17 AC 191 ms
26,204 KB
testcase_18 AC 145 ms
23,276 KB
testcase_19 AC 152 ms
23,580 KB
testcase_20 AC 89 ms
16,120 KB
testcase_21 AC 88 ms
16,120 KB
testcase_22 AC 87 ms
16,120 KB
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
if table[x.fdiv(2)]
    if table[x/2] == 1
        count += 1
    else
        count += table[x/2]**2 - table[x/2]
    end
end
table.keys.each do |k|
    if table[x.fdiv(2)] && table[x/2] == k
        next
    end
    if x - k < 0
        next
    end
    count = table[k] * (table[x - k] || 0)
end
puts count
0