結果
問題 |
No.723 2つの数の和
|
ユーザー |
![]() |
提出日時 | 2019-11-12 00:42:49 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 645 bytes |
コンパイル時間 | 2,507 ms |
コンパイル使用メモリ | 76,536 KB |
実行使用メモリ | 63,240 KB |
最終ジャッジ日時 | 2024-09-15 11:19:37 |
合計ジャッジ時間 | 17,085 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 WA * 5 |
ソースコード
import java.util.*; public class Main { public static void main (String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int x = sc.nextInt(); TreeMap<Integer, Integer> map = new TreeMap<>(); for (int i = 0; i < n; i++) { int a = sc.nextInt(); if (map.containsKey(a)) { map.put(a, map.get(a) + 1); } else { map.put(a, 1); } } long total = 0; for (int y : map.keySet()) { if (y >= x) { break; } if (map.containsKey(x - y)) { total += map.get(y) * map.get(x - y); } } System.out.println(total); } }