結果

問題 No.723 2つの数の和
ユーザー htensaihtensai
提出日時 2019-11-12 00:48:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 758 ms / 2,000 ms
コード長 642 bytes
コンパイル時間 2,113 ms
コンパイル使用メモリ 73,232 KB
実行使用メモリ 67,568 KB
最終ジャッジ日時 2023-10-13 14:44:33
合計ジャッジ時間 15,452 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,848 KB
testcase_01 AC 124 ms
56,232 KB
testcase_02 AC 123 ms
55,852 KB
testcase_03 AC 612 ms
63,956 KB
testcase_04 AC 758 ms
67,152 KB
testcase_05 AC 673 ms
66,244 KB
testcase_06 AC 746 ms
66,940 KB
testcase_07 AC 473 ms
62,732 KB
testcase_08 AC 555 ms
61,024 KB
testcase_09 AC 748 ms
66,916 KB
testcase_10 AC 503 ms
60,200 KB
testcase_11 AC 276 ms
60,360 KB
testcase_12 AC 543 ms
62,700 KB
testcase_13 AC 758 ms
67,448 KB
testcase_14 AC 382 ms
60,336 KB
testcase_15 AC 507 ms
62,688 KB
testcase_16 AC 590 ms
62,900 KB
testcase_17 AC 699 ms
65,016 KB
testcase_18 AC 512 ms
60,820 KB
testcase_19 AC 573 ms
60,560 KB
testcase_20 AC 125 ms
56,136 KB
testcase_21 AC 125 ms
56,148 KB
testcase_22 AC 126 ms
56,160 KB
testcase_23 AC 752 ms
67,568 KB
testcase_24 AC 414 ms
61,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
	}
}
0