結果

問題 No.133 カードゲーム
ユーザー htensaihtensai
提出日時 2020-02-05 14:47:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 5,000 ms
コード長 1,481 bytes
コンパイル時間 2,018 ms
コンパイル使用メモリ 77,020 KB
実行使用メモリ 57,616 KB
最終ジャッジ日時 2023-10-23 19:35:56
合計ジャッジ時間 6,289 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
57,512 KB
testcase_01 AC 125 ms
57,340 KB
testcase_02 AC 123 ms
57,200 KB
testcase_03 AC 122 ms
57,488 KB
testcase_04 AC 123 ms
57,168 KB
testcase_05 AC 116 ms
56,144 KB
testcase_06 AC 119 ms
56,184 KB
testcase_07 AC 125 ms
57,616 KB
testcase_08 AC 124 ms
57,428 KB
testcase_09 AC 126 ms
57,540 KB
testcase_10 AC 128 ms
57,280 KB
testcase_11 AC 115 ms
56,104 KB
testcase_12 AC 127 ms
57,384 KB
testcase_13 AC 127 ms
57,476 KB
testcase_14 AC 125 ms
57,580 KB
testcase_15 AC 126 ms
55,316 KB
testcase_16 AC 126 ms
57,348 KB
testcase_17 AC 126 ms
57,492 KB
testcase_18 AC 118 ms
56,232 KB
testcase_19 AC 128 ms
57,488 KB
testcase_20 AC 125 ms
57,320 KB
testcase_21 AC 124 ms
57,308 KB
testcase_22 AC 132 ms
57,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int[] aList;
    static int[] bList;
    static int count;
    static int n;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        aList = new int[n];
        bList = new int[n];
        for (int i = 0; i < n; i++) {
            aList[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            bList[i] = sc.nextInt();
        }
        calc(0, 0);
        System.out.println(count / (kaijo(n) * kaijo(n)));
    }
    
    static double kaijo(int x) {
        if (x == 1) {
            return 1;
        } else {
            return x * kaijo(x - 1);
        }
    }
    
    static void calc(int idx, int win) {
        if (idx == n) {
            if (win * 2 > n) {
                count++;
            }
            return;
        }
        for (int i = 0; i < n; i++) {
            if (aList[i] == 0) {
                continue;
            }
            int x = aList[i];
            aList[i] = 0;
            for (int j = 0; j < n; j++) {
                if (bList[j] == 0) {
                    continue;
                }
                int y = bList[j];
                bList[j] = 0;
                int tmp = win;
                if (x > y) {
                    tmp++;
                }
                calc(idx + 1, tmp);
                
                bList[j] = y;
            }
            aList[i] = x;
        }
    }
}
0