結果
| 問題 | No.1279 Array Battle | 
| コンテスト | |
| ユーザー |  tenten | 
| 提出日時 | 2020-11-09 09:16:11 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 180 ms / 2,000 ms | 
| コード長 | 1,315 bytes | 
| コンパイル時間 | 2,475 ms | 
| コンパイル使用メモリ | 77,052 KB | 
| 実行使用メモリ | 41,708 KB | 
| 最終ジャッジ日時 | 2024-07-22 15:57:35 | 
| 合計ジャッジ時間 | 6,047 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 20 | 
ソースコード
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;
        }
    }
}
            
            
            
        