結果

問題 No.133 カードゲーム
ユーザー tenten
提出日時 2021-02-04 08:37:22
言語 Java
(openjdk 23)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 1,631 bytes
コンパイル時間 2,159 ms
コンパイル使用メモリ 78,048 KB
実行使用メモリ 54,572 KB
最終ジャッジ日時 2024-06-30 14:06:59
合計ジャッジ時間 6,264 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] as = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }
        int[] bs = new int[n];
        for (int i = 0; i < n; i++) {
            bs[i] = sc.nextInt();
        }
        ArrayList<int[]> permuration = getPermuration(n);
        int size = permuration.size();
        int win = 0;
        for (int[] aArr : permuration) {
            for (int[] bArr : permuration) {
                int count = 0;
                for (int i = 0; i < n; i++) {
                    if (as[aArr[i]] > bs[bArr[i]]) {
                        count++;
                    }
                }
                if (count * 2 > n) {
                    win++;
                }
            }
        }
        System.out.println((double)win / size / size);
    }
    
    static ArrayList<int[]> getPermuration(int n) {
        ArrayList<int[]> ans = new ArrayList<>();
        makePermuration(0, new int[n], new boolean[n], ans, n);
        return ans;
    }
    
    static void makePermuration(int idx, int[] arr, boolean[] used, ArrayList<int[]> ans, int size) {
        if (idx == size) {
            ans.add((int[])arr.clone());
            return;
        }
        for (int i = 0; i < size; i++) {
            if (used[i]) {
                continue;
            }
            used[i] = true;
            arr[idx] = i;
            makePermuration(idx + 1, arr, used, ans, size);
            used[i] = false;
        }
    }
}
0