結果

問題 No.989 N×Mマス計算(K以上)
ユーザー htensaihtensai
提出日時 2020-02-21 08:41:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 739 ms / 2,000 ms
コード長 1,252 bytes
コンパイル時間 2,452 ms
コンパイル使用メモリ 77,688 KB
実行使用メモリ 51,728 KB
最終ジャッジ日時 2024-04-17 06:44:11
合計ジャッジ時間 10,564 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
40,088 KB
testcase_01 AC 120 ms
41,176 KB
testcase_02 AC 141 ms
41,772 KB
testcase_03 AC 143 ms
41,816 KB
testcase_04 AC 119 ms
40,128 KB
testcase_05 AC 131 ms
41,260 KB
testcase_06 AC 135 ms
41,496 KB
testcase_07 AC 131 ms
41,536 KB
testcase_08 AC 137 ms
41,356 KB
testcase_09 AC 140 ms
41,428 KB
testcase_10 AC 654 ms
49,620 KB
testcase_11 AC 592 ms
48,776 KB
testcase_12 AC 556 ms
48,176 KB
testcase_13 AC 539 ms
48,564 KB
testcase_14 AC 739 ms
51,728 KB
testcase_15 AC 474 ms
48,476 KB
testcase_16 AC 584 ms
49,028 KB
testcase_17 AC 526 ms
48,436 KB
testcase_18 AC 525 ms
48,512 KB
testcase_19 AC 558 ms
48,908 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