結果

問題 No.723 2つの数の和
ユーザー Pump0129Pump0129
提出日時 2018-11-28 00:41:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 824 ms / 2,000 ms
コード長 1,188 bytes
コンパイル時間 2,515 ms
コンパイル使用メモリ 75,676 KB
実行使用メモリ 77,660 KB
最終ジャッジ日時 2023-09-07 03:01:32
合計ジャッジ時間 16,484 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
56,384 KB
testcase_01 AC 128 ms
55,976 KB
testcase_02 AC 127 ms
55,836 KB
testcase_03 AC 660 ms
68,172 KB
testcase_04 AC 820 ms
77,132 KB
testcase_05 AC 766 ms
72,220 KB
testcase_06 AC 796 ms
73,060 KB
testcase_07 AC 494 ms
64,824 KB
testcase_08 AC 551 ms
65,124 KB
testcase_09 AC 773 ms
77,064 KB
testcase_10 AC 505 ms
64,772 KB
testcase_11 AC 278 ms
61,404 KB
testcase_12 AC 562 ms
67,036 KB
testcase_13 AC 824 ms
77,440 KB
testcase_14 AC 395 ms
62,600 KB
testcase_15 AC 524 ms
65,056 KB
testcase_16 AC 614 ms
67,224 KB
testcase_17 AC 734 ms
72,324 KB
testcase_18 AC 536 ms
62,996 KB
testcase_19 AC 629 ms
63,872 KB
testcase_20 AC 126 ms
56,044 KB
testcase_21 AC 126 ms
55,976 KB
testcase_22 AC 125 ms
55,640 KB
testcase_23 AC 674 ms
77,660 KB
testcase_24 AC 436 ms
62,488 KB
権限があれば一括ダウンロードができます

ソースコード

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