結果

問題 No.723 2つの数の和
ユーザー tentententen
提出日時 2023-04-14 14:52:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 292 ms / 2,000 ms
コード長 1,854 bytes
コンパイル時間 2,618 ms
コンパイル使用メモリ 91,616 KB
実行使用メモリ 52,004 KB
最終ジャッジ日時 2024-04-18 13:22:36
合計ジャッジ時間 8,704 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
36,984 KB
testcase_01 AC 52 ms
37,216 KB
testcase_02 AC 55 ms
37,232 KB
testcase_03 AC 261 ms
47,796 KB
testcase_04 AC 275 ms
48,948 KB
testcase_05 AC 260 ms
48,512 KB
testcase_06 AC 269 ms
48,304 KB
testcase_07 AC 201 ms
45,496 KB
testcase_08 AC 232 ms
46,396 KB
testcase_09 AC 279 ms
48,948 KB
testcase_10 AC 194 ms
45,608 KB
testcase_11 AC 124 ms
40,376 KB
testcase_12 AC 226 ms
47,076 KB
testcase_13 AC 284 ms
48,900 KB
testcase_14 AC 166 ms
44,732 KB
testcase_15 AC 222 ms
45,884 KB
testcase_16 AC 237 ms
47,396 KB
testcase_17 AC 270 ms
48,860 KB
testcase_18 AC 199 ms
44,900 KB
testcase_19 AC 226 ms
45,172 KB
testcase_20 AC 54 ms
37,356 KB
testcase_21 AC 54 ms
36,884 KB
testcase_22 AC 53 ms
37,156 KB
testcase_23 AC 292 ms
52,004 KB
testcase_24 AC 187 ms
46,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int target = sc.nextInt();
        HashMap<Integer, Long> counts = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            counts.put(x, counts.getOrDefault(x, 0L) + 1);
        }
        long ans = 0;
        for (int x : counts.keySet()) {
            ans += counts.get(x) * counts.getOrDefault(target - x, 0L);
        }
        System.out.println(ans);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0