結果

問題 No.723 2つの数の和
ユーザー htensaihtensai
提出日時 2019-11-12 00:44:02
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 644 bytes
コンパイル時間 2,816 ms
コンパイル使用メモリ 73,304 KB
実行使用メモリ 69,476 KB
最終ジャッジ日時 2023-10-13 14:34:56
合計ジャッジ時間 15,341 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,044 KB
testcase_01 AC 126 ms
56,084 KB
testcase_02 AC 123 ms
55,792 KB
testcase_03 AC 628 ms
64,088 KB
testcase_04 AC 761 ms
67,156 KB
testcase_05 AC 695 ms
67,064 KB
testcase_06 AC 732 ms
67,376 KB
testcase_07 AC 502 ms
63,452 KB
testcase_08 AC 535 ms
62,404 KB
testcase_09 AC 772 ms
67,100 KB
testcase_10 AC 513 ms
60,504 KB
testcase_11 AC 285 ms
59,984 KB
testcase_12 AC 553 ms
62,512 KB
testcase_13 AC 802 ms
66,952 KB
testcase_14 AC 398 ms
60,308 KB
testcase_15 AC 547 ms
62,144 KB
testcase_16 AC 587 ms
62,184 KB
testcase_17 AC 703 ms
65,616 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 118 ms
56,272 KB
testcase_21 AC 120 ms
55,844 KB
testcase_22 AC 119 ms
56,048 KB
testcase_23 AC 732 ms
69,476 KB
testcase_24 AC 424 ms
60,284 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, 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);
	}
}
0