結果

問題 No.133 カードゲーム
ユーザー tentententen
提出日時 2021-02-04 08:37:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 1,631 bytes
コンパイル時間 3,416 ms
コンパイル使用メモリ 74,536 KB
実行使用メモリ 56,212 KB
最終ジャッジ日時 2023-09-13 03:53:45
合計ジャッジ時間 6,311 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,212 KB
testcase_01 AC 119 ms
55,780 KB
testcase_02 AC 117 ms
56,016 KB
testcase_03 AC 119 ms
55,792 KB
testcase_04 AC 119 ms
55,740 KB
testcase_05 AC 121 ms
55,960 KB
testcase_06 AC 120 ms
56,124 KB
testcase_07 AC 120 ms
54,344 KB
testcase_08 AC 120 ms
55,928 KB
testcase_09 AC 119 ms
55,860 KB
testcase_10 AC 118 ms
55,644 KB
testcase_11 AC 121 ms
55,720 KB
testcase_12 AC 121 ms
55,956 KB
testcase_13 AC 120 ms
55,816 KB
testcase_14 AC 121 ms
56,028 KB
testcase_15 AC 120 ms
55,964 KB
testcase_16 AC 120 ms
55,780 KB
testcase_17 AC 121 ms
55,724 KB
testcase_18 AC 123 ms
55,960 KB
testcase_19 AC 121 ms
55,468 KB
testcase_20 AC 121 ms
56,032 KB
testcase_21 AC 123 ms
55,808 KB
testcase_22 AC 120 ms
55,744 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[] 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