結果
問題 |
No.723 2つの数の和
|
ユーザー |
![]() |
提出日時 | 2019-11-12 00:44:02 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 644 bytes |
コンパイル時間 | 2,444 ms |
コンパイル使用メモリ | 76,620 KB |
実行使用メモリ | 63,320 KB |
最終ジャッジ日時 | 2024-09-15 11:21:06 |
合計ジャッジ時間 | 16,598 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 WA * 2 |
ソースコード
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); } }