結果

問題 No.1279 Array Battle
ユーザー tentententen
提出日時 2020-11-09 09:16:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 1,315 bytes
コンパイル時間 4,139 ms
コンパイル使用メモリ 73,964 KB
実行使用メモリ 58,240 KB
最終ジャッジ日時 2023-09-29 21:57:50
合計ジャッジ時間 6,831 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,716 KB
testcase_01 AC 119 ms
55,816 KB
testcase_02 AC 121 ms
56,508 KB
testcase_03 AC 119 ms
55,788 KB
testcase_04 AC 119 ms
55,968 KB
testcase_05 AC 124 ms
55,992 KB
testcase_06 AC 120 ms
55,692 KB
testcase_07 AC 119 ms
55,780 KB
testcase_08 AC 119 ms
56,060 KB
testcase_09 AC 120 ms
55,864 KB
testcase_10 AC 120 ms
56,088 KB
testcase_11 AC 121 ms
55,708 KB
testcase_12 AC 137 ms
56,404 KB
testcase_13 AC 165 ms
56,588 KB
testcase_14 AC 174 ms
58,240 KB
testcase_15 AC 164 ms
55,936 KB
testcase_16 AC 156 ms
56,312 KB
testcase_17 AC 176 ms
56,480 KB
testcase_18 AC 157 ms
56,356 KB
testcase_19 AC 157 ms
56,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int n;
    static int[] aArr;
    static int[] bArr;
    static int max = 0;
    static int count = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        aArr = new int[n];
        for (int i = 0; i < n; i++) {
            aArr[i] = sc.nextInt();
        }
        bArr = new int[n];
        for (int i = 0; i < n; i++) {
            bArr[i] = sc.nextInt();
        }
        boolean[] used = new boolean[n];
        int[] arr = new int[n];
        setPerm(used, arr, 0);
        System.out.println(count);
    }
    
    static void setPerm(boolean[] used, int[] arr, int idx) {
        if (idx == n) {
            int value = 0;
            for (int i = 0; i < n; i++) {
                value += Math.max(0, bArr[i] - aArr[arr[i]]);
            }
            if (max < value) {
                max = value;
                count = 1;
            } else if (max == value) {
                count++;
            }
            return;
        }
        for (int i = 0; i < n; i++) {
            if (used[i]) {
                continue;
            }
            used[i] = true;
            arr[idx] = i;
            setPerm(used, arr, idx + 1);
            used[i] = false;
        }
    }
}
0