結果
問題 | No.723 2つの数の和 |
ユーザー |
![]() |
提出日時 | 2019-11-12 00:48:04 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 877 ms / 2,000 ms |
コード長 | 642 bytes |
コンパイル時間 | 2,283 ms |
コンパイル使用メモリ | 76,988 KB |
実行使用メモリ | 63,296 KB |
最終ジャッジ日時 | 2024-09-15 11:29:54 |
合計ジャッジ時間 | 16,437 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
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, Long> 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, 1L); } } 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); } }