結果

問題 No.723 2つの数の和
ユーザー htensaihtensai
提出日時 2019-11-12 00:42:49
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 645 bytes
コンパイル時間 3,835 ms
コンパイル使用メモリ 72,336 KB
実行使用メモリ 69,356 KB
最終ジャッジ日時 2023-10-13 14:33:30
合計ジャッジ時間 17,704 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,672 KB
testcase_01 AC 125 ms
56,332 KB
testcase_02 AC 123 ms
55,776 KB
testcase_03 AC 640 ms
64,296 KB
testcase_04 AC 781 ms
67,348 KB
testcase_05 AC 693 ms
67,084 KB
testcase_06 AC 738 ms
67,372 KB
testcase_07 AC 468 ms
62,944 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 505 ms
60,356 KB
testcase_11 AC 271 ms
60,120 KB
testcase_12 AC 553 ms
62,292 KB
testcase_13 AC 789 ms
69,092 KB
testcase_14 AC 388 ms
60,496 KB
testcase_15 AC 507 ms
63,120 KB
testcase_16 AC 599 ms
63,068 KB
testcase_17 AC 705 ms
65,380 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 125 ms
56,232 KB
testcase_22 AC 122 ms
56,028 KB
testcase_23 AC 735 ms
69,356 KB
testcase_24 AC 392 ms
61,108 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