結果

問題 No.723 2つの数の和
ユーザー YoteichiYoteichi
提出日時 2018-08-04 04:22:13
言語 Ruby
(3.3.0)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 436 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 11,936 KB
実行使用メモリ 38,796 KB
最終ジャッジ日時 2023-10-19 21:43:07
合計ジャッジ時間 5,090 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
16,116 KB
testcase_01 AC 93 ms
16,116 KB
testcase_02 AC 93 ms
16,116 KB
testcase_03 AC 184 ms
25,388 KB
testcase_04 AC 217 ms
32,000 KB
testcase_05 AC 194 ms
26,492 KB
testcase_06 AC 206 ms
27,128 KB
testcase_07 AC 141 ms
23,332 KB
testcase_08 AC 151 ms
24,920 KB
testcase_09 AC 210 ms
32,664 KB
testcase_10 AC 146 ms
22,820 KB
testcase_11 AC 103 ms
17,224 KB
testcase_12 AC 154 ms
25,924 KB
testcase_13 AC 226 ms
32,936 KB
testcase_14 AC 121 ms
19,536 KB
testcase_15 AC 148 ms
24,464 KB
testcase_16 AC 180 ms
27,356 KB
testcase_17 AC 203 ms
26,200 KB
testcase_18 AC 152 ms
23,272 KB
testcase_19 AC 154 ms
23,556 KB
testcase_20 AC 99 ms
16,116 KB
testcase_21 AC 94 ms
16,116 KB
testcase_22 AC 91 ms
16,116 KB
testcase_23 AC 264 ms
38,796 KB
testcase_24 AC 133 ms
21,384 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
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