結果

問題 No.723 2つの数の和
ユーザー tentententen
提出日時 2022-08-03 09:11:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 259 ms / 2,000 ms
コード長 1,276 bytes
コンパイル時間 2,035 ms
コンパイル使用メモリ 74,644 KB
実行使用メモリ 62,504 KB
最終ジャッジ日時 2023-10-09 23:25:41
合計ジャッジ時間 7,980 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,208 KB
testcase_01 AC 40 ms
49,492 KB
testcase_02 AC 40 ms
49,192 KB
testcase_03 AC 225 ms
58,420 KB
testcase_04 AC 246 ms
58,732 KB
testcase_05 AC 227 ms
58,464 KB
testcase_06 AC 236 ms
58,452 KB
testcase_07 AC 198 ms
56,236 KB
testcase_08 AC 200 ms
56,232 KB
testcase_09 AC 259 ms
58,332 KB
testcase_10 AC 194 ms
56,328 KB
testcase_11 AC 107 ms
52,308 KB
testcase_12 AC 203 ms
58,040 KB
testcase_13 AC 258 ms
58,228 KB
testcase_14 AC 146 ms
55,264 KB
testcase_15 AC 200 ms
57,884 KB
testcase_16 AC 230 ms
58,328 KB
testcase_17 AC 239 ms
58,864 KB
testcase_18 AC 184 ms
56,124 KB
testcase_19 AC 204 ms
55,620 KB
testcase_20 AC 42 ms
49,376 KB
testcase_21 AC 42 ms
49,156 KB
testcase_22 AC 40 ms
49,208 KB
testcase_23 AC 257 ms
62,504 KB
testcase_24 AC 162 ms
56,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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> count = new HashMap<>();
        while (n-- > 0) {
            int x = sc.nextInt();
            count.put(x, count.getOrDefault(x, 0L) + 1);
        }
        long ans = 0;
        for (int x : count.keySet()) {
            ans += count.get(x) * count.getOrDefault(target - x, 0L);
        }
        System.out.println(ans);
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0