結果

問題 No.133 カードゲーム
ユーザー ameame
提出日時 2019-08-27 12:29:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 121 ms / 5,000 ms
コード長 1,529 bytes
コンパイル時間 2,396 ms
コンパイル使用メモリ 74,136 KB
実行使用メモリ 56,288 KB
最終ジャッジ日時 2023-08-09 02:19:01
合計ジャッジ時間 6,207 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
56,036 KB
testcase_01 AC 116 ms
55,812 KB
testcase_02 AC 118 ms
56,100 KB
testcase_03 AC 119 ms
55,988 KB
testcase_04 AC 119 ms
56,096 KB
testcase_05 AC 117 ms
55,896 KB
testcase_06 AC 115 ms
55,512 KB
testcase_07 AC 117 ms
56,276 KB
testcase_08 AC 114 ms
55,956 KB
testcase_09 AC 112 ms
55,604 KB
testcase_10 AC 114 ms
56,264 KB
testcase_11 AC 115 ms
55,920 KB
testcase_12 AC 119 ms
55,700 KB
testcase_13 AC 119 ms
56,264 KB
testcase_14 AC 116 ms
55,900 KB
testcase_15 AC 119 ms
56,076 KB
testcase_16 AC 121 ms
56,220 KB
testcase_17 AC 114 ms
56,156 KB
testcase_18 AC 115 ms
56,288 KB
testcase_19 AC 117 ms
56,092 KB
testcase_20 AC 114 ms
55,852 KB
testcase_21 AC 116 ms
55,940 KB
testcase_22 AC 120 ms
56,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

class Main {
    static int n;
    static int[] b;
    static int[] a;
    static long win = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        a = new int[n];
        b = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            b[i] = sc.nextInt();
        }
        boolean used[] = new boolean[n];
        int[] tmp = new int[n];
        long battlenum[] = new long[n + 10];
        battlenum[0] = 1;
        battlenum[1] = 1;
        for (int i = 2; i < 10; i++) {
            battlenum[i] = i * battlenum[i - 1];
        }
        permutation(a, tmp, used, 0);
        System.out.println(win * 1.0 / battlenum[n]);

        sc.close();
    }

    public static void permutation(int[] origin, int[] tmp, boolean[] used, int index) {
        if (index == n) {
            // 処理
            Battle(tmp);
            return;
        }
        for (int i = 0; i < n; i++) {
            if (used[i])
                continue;
            tmp[index] = origin[i];
            used[i] = true;
            permutation(origin, tmp, used, index + 1);
            used[i] = false;
        }
    }

    public static void Battle(int[] op) {
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (op[i] > b[i]) {
                cnt++;
            }
        }
        if (cnt > n / 2) {
            win++;
        }
    }
}
0