結果
問題 |
No.723 2つの数の和
|
ユーザー |
|
提出日時 | 2018-10-04 00:49:19 |
言語 | Ruby (3.4.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 422 bytes |
コンパイル時間 | 54 ms |
コンパイル使用メモリ | 7,680 KB |
実行使用メモリ | 24,960 KB |
最終ジャッジ日時 | 2024-10-12 10:41:11 |
合計ジャッジ時間 | 4,710 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 RE * 3 |
コンパイルメッセージ
Syntax OK
ソースコード
#!/usr/bin/ruby N, X = gets.split.map(&:to_i) a = gets.split.map(&:to_i) hash = {} a.each do |a| hash[a] ||= 0 hash[a] += 1 end count = 0 i = 0 while i < a.length do num1 = a[i] num2 = X - num1 if num1 == num2 if hash[num2] >= 2 count += hash[num]-1 elsif hash[num2] >= 1 count += hash[num2] end else if hash[num2] count += hash[num2] end end i += 1 end puts count