結果

問題 No.989 N×Mマス計算(K以上)
ユーザー htensaihtensai
提出日時 2020-02-21 08:41:40
言語 Java19
(openjdk 21)
結果
AC  
実行時間 708 ms / 2,000 ms
コード長 1,252 bytes
コンパイル時間 5,186 ms
コンパイル使用メモリ 74,108 KB
実行使用メモリ 61,372 KB
最終ジャッジ日時 2023-07-30 04:52:44
合計ジャッジ時間 13,883 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,760 KB
testcase_01 AC 123 ms
55,896 KB
testcase_02 AC 133 ms
55,996 KB
testcase_03 AC 137 ms
55,772 KB
testcase_04 AC 130 ms
55,864 KB
testcase_05 AC 136 ms
55,968 KB
testcase_06 AC 134 ms
55,908 KB
testcase_07 AC 132 ms
55,788 KB
testcase_08 AC 134 ms
55,812 KB
testcase_09 AC 142 ms
55,608 KB
testcase_10 AC 568 ms
61,268 KB
testcase_11 AC 549 ms
60,772 KB
testcase_12 AC 596 ms
61,076 KB
testcase_13 AC 502 ms
60,764 KB
testcase_14 AC 708 ms
61,372 KB
testcase_15 AC 418 ms
60,808 KB
testcase_16 AC 541 ms
60,736 KB
testcase_17 AC 493 ms
60,528 KB
testcase_18 AC 490 ms
60,964 KB
testcase_19 AC 589 ms
60,920 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 m = sc.nextInt();
        int k = sc.nextInt();
        char op = sc.next().charAt(0);
        long[] arrB = new long[m];
        for (int i = 0; i < m; i++) {
            arrB[i] = sc.nextInt();
        }
        Arrays.sort(arrB);
        long[] arrA = new long[n];
        for (int i = 0; i < n; i++) {
            arrA[i] = sc.nextInt();
        }
        Arrays.sort(arrA);
        int idxB = m - 1;
        long count = 0;
        if (op == '+') {
            for (int i = 0; i < n; i++) {
                while (idxB >= 1 && arrB[idxB - 1] + arrA[i] >= k) {
                    idxB--;
                }
                if (arrB[idxB] + arrA[i] >= k) {
                    count += m - idxB;
                }
            }
        } else {
            for (int i = 0; i < n; i++) {
                while (idxB >= 1 && arrB[idxB - 1] * arrA[i] >= k) {
                    idxB--;
                }
                if (arrB[idxB] * arrA[i] >= k) {
                    count += m - idxB;
                }
            }
         }
         System.out.println(count);
    }
}
0