結果

問題 No.723 2つの数の和
ユーザー ikdikd
提出日時 2017-08-07 15:58:44
言語 Ruby
(3.2.2)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 185 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 11,292 KB
実行使用メモリ 22,448 KB
最終ジャッジ日時 2023-08-02 03:17:16
合計ジャッジ時間 4,716 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
15,088 KB
testcase_01 AC 72 ms
15,132 KB
testcase_02 AC 73 ms
15,160 KB
testcase_03 AC 115 ms
20,416 KB
testcase_04 AC 130 ms
21,852 KB
testcase_05 AC 121 ms
21,196 KB
testcase_06 AC 122 ms
21,504 KB
testcase_07 AC 102 ms
18,164 KB
testcase_08 AC 105 ms
18,732 KB
testcase_09 AC 138 ms
22,196 KB
testcase_10 AC 101 ms
18,192 KB
testcase_11 AC 85 ms
16,292 KB
testcase_12 AC 108 ms
19,020 KB
testcase_13 AC 134 ms
22,316 KB
testcase_14 AC 92 ms
17,296 KB
testcase_15 AC 101 ms
18,320 KB
testcase_16 AC 110 ms
19,892 KB
testcase_17 AC 124 ms
20,916 KB
testcase_18 AC 128 ms
21,412 KB
testcase_19 AC 133 ms
22,420 KB
testcase_20 AC 74 ms
15,152 KB
testcase_21 AC 69 ms
15,060 KB
testcase_22 AC 73 ms
15,128 KB
testcase_23 AC 133 ms
22,448 KB
testcase_24 AC 96 ms
17,580 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)

cnt=Array.new(a.max+1){0}
a.each{|e| cnt[e]+=1}
ans=0
a.each do |e|
  next if x-e<0 or x-e>=cnt.size
  ans+=cnt[x-e]
end

puts ans
0