結果
| 問題 | No.133 カードゲーム | 
| コンテスト | |
| ユーザー |  htensai | 
| 提出日時 | 2020-02-05 14:47:48 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 135 ms / 5,000 ms | 
| コード長 | 1,481 bytes | 
| コンパイル時間 | 2,202 ms | 
| コンパイル使用メモリ | 76,676 KB | 
| 実行使用メモリ | 54,288 KB | 
| 最終ジャッジ日時 | 2024-09-22 13:19:10 | 
| 合計ジャッジ時間 | 6,222 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 19 | 
ソースコード
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;
        }
    }
}
            
            
            
        