結果

問題 No.723 2つの数の和
ユーザー ikdikd
提出日時 2017-08-07 15:58:44
言語 Ruby
(3.3.0)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 185 bytes
コンパイル時間 47 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-04-20 03:34:52
合計ジャッジ時間 4,261 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
12,032 KB
testcase_01 AC 78 ms
12,032 KB
testcase_02 AC 77 ms
12,160 KB
testcase_03 AC 127 ms
17,792 KB
testcase_04 AC 137 ms
18,560 KB
testcase_05 AC 132 ms
18,176 KB
testcase_06 AC 141 ms
18,176 KB
testcase_07 AC 107 ms
15,360 KB
testcase_08 AC 109 ms
15,872 KB
testcase_09 AC 135 ms
18,816 KB
testcase_10 AC 109 ms
14,848 KB
testcase_11 AC 91 ms
13,184 KB
testcase_12 AC 114 ms
16,128 KB
testcase_13 AC 140 ms
19,456 KB
testcase_14 AC 100 ms
13,952 KB
testcase_15 AC 109 ms
15,616 KB
testcase_16 AC 121 ms
17,152 KB
testcase_17 AC 130 ms
17,792 KB
testcase_18 AC 133 ms
18,688 KB
testcase_19 AC 141 ms
19,200 KB
testcase_20 AC 78 ms
12,160 KB
testcase_21 AC 81 ms
12,160 KB
testcase_22 AC 81 ms
12,160 KB
testcase_23 AC 144 ms
19,456 KB
testcase_24 AC 99 ms
14,464 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