結果

問題 No.723 2つの数の和
ユーザー Pump0129
提出日時 2018-11-28 00:41:51
言語 Java
(openjdk 23)
結果
AC  
実行時間 852 ms / 2,000 ms
コード長 1,188 bytes
コンパイル時間 2,787 ms
コンパイル使用メモリ 79,456 KB
実行使用メモリ 67,876 KB
最終ジャッジ日時 2024-06-24 21:42:33
合計ジャッジ時間 15,380 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

package net.ipipip0129.yukicoder.No723;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int num_len = scan.nextInt();
        int base_num = scan.nextInt();

        int[] num_array = new int[num_len];
        Map<Integer, List<Integer>> num_map = new HashMap<>();

        long ans_cnt = 0;

        for (int i = 0; i < num_len; i++) {
            int a = scan.nextInt();
            num_array[i] = a;

            List<Integer> li;
            if (num_map.containsKey(a)) li = num_map.get(a);
            else li = new ArrayList<>();
            li.add(i);
            num_map.put(a, li);
        }

        Arrays.sort(num_array);

        for (int i = 0; i < num_len; i++) {
            int sub = base_num - num_array[i];
            if (num_array[i] <= base_num) {
                if (num_map.containsKey(sub)) {
                    List<Integer> li = num_map.get(sub);
                    ans_cnt += li.size();
                }
            } else {
                break;
            }
        }

        System.out.println(ans_cnt);
    }
}
0