結果

問題 No.1282 Display Elements
ユーザー tentententen
提出日時 2020-11-09 12:43:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,235 ms / 2,000 ms
コード長 1,333 bytes
コンパイル時間 2,723 ms
コンパイル使用メモリ 75,272 KB
実行使用メモリ 65,516 KB
最終ジャッジ日時 2023-09-29 22:01:40
合計ジャッジ時間 14,989 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
56,352 KB
testcase_01 AC 113 ms
55,964 KB
testcase_02 AC 119 ms
55,540 KB
testcase_03 AC 120 ms
56,088 KB
testcase_04 AC 116 ms
55,820 KB
testcase_05 AC 111 ms
56,560 KB
testcase_06 AC 116 ms
55,888 KB
testcase_07 AC 109 ms
56,416 KB
testcase_08 AC 107 ms
56,128 KB
testcase_09 AC 117 ms
55,928 KB
testcase_10 AC 190 ms
59,292 KB
testcase_11 AC 182 ms
58,404 KB
testcase_12 AC 136 ms
55,988 KB
testcase_13 AC 171 ms
56,120 KB
testcase_14 AC 183 ms
58,860 KB
testcase_15 AC 1,039 ms
65,316 KB
testcase_16 AC 599 ms
61,484 KB
testcase_17 AC 920 ms
64,768 KB
testcase_18 AC 731 ms
64,632 KB
testcase_19 AC 1,224 ms
65,028 KB
testcase_20 AC 1,235 ms
64,972 KB
testcase_21 AC 1,075 ms
64,676 KB
testcase_22 AC 1,059 ms
65,516 KB
testcase_23 AC 1,214 ms
65,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] aArr = new int[n];
        for (int i = 0; i < n; i++) {
            aArr[i] = sc.nextInt();
        }
        Arrays.sort(aArr);
        int[] bArr = new int[n];
        for (int i = 0; i < n; i++) {
            bArr[i] = sc.nextInt();
        }
        ArrayList<Integer> used = new ArrayList<>();
        used.add(Integer.MIN_VALUE);
        used.add(Integer.MAX_VALUE);
        long point = 0;
        for (int i = 0; i < n; i++) {
            int left = 0;
            int right = used.size();
            while (right - left > 1) {
                int m = (left + right) / 2;
                if (used.get(m) < bArr[i]) {
                    left = m;
                } else {
                    right = m;
                }
            }
            used.add(right, bArr[i]);
            int min = 0;
            int max = used.size();
            while (max - min > 1) {
                int m = (min + max) / 2;
                if (used.get(m) < aArr[i]) {
                    min = m;
                } else {
                    max = m;
                }
            }
            point += min;
        }
        System.out.println(point);
    }
}
0