結果

問題 No.133 カードゲーム
ユーザー YamaKasaYamaKasa
提出日時 2018-07-15 21:53:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 157 ms / 5,000 ms
コード長 1,525 bytes
コンパイル時間 3,583 ms
コンパイル使用メモリ 73,140 KB
実行使用メモリ 56,104 KB
最終ジャッジ日時 2023-08-07 04:08:49
合計ジャッジ時間 8,473 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 150 ms
55,956 KB
testcase_01 AC 148 ms
55,936 KB
testcase_02 AC 148 ms
55,672 KB
testcase_03 AC 157 ms
55,784 KB
testcase_04 AC 150 ms
56,104 KB
testcase_05 AC 151 ms
55,764 KB
testcase_06 AC 153 ms
55,492 KB
testcase_07 AC 152 ms
53,784 KB
testcase_08 AC 151 ms
39,232 KB
testcase_09 AC 150 ms
39,136 KB
testcase_10 AC 151 ms
39,820 KB
testcase_11 AC 154 ms
39,296 KB
testcase_12 AC 153 ms
39,204 KB
testcase_13 AC 149 ms
39,480 KB
testcase_14 AC 150 ms
39,528 KB
testcase_15 AC 150 ms
39,484 KB
testcase_16 AC 150 ms
39,236 KB
testcase_17 AC 152 ms
39,324 KB
testcase_18 AC 151 ms
55,736 KB
testcase_19 AC 151 ms
39,876 KB
testcase_20 AC 151 ms
55,748 KB
testcase_21 AC 152 ms
55,696 KB
testcase_22 AC 152 ms
55,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static int[][] list;
	static int index = 0;
	static int N;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		N = scan.nextInt();
		int []A = new int[N];
		int []B = new int[N];

		for(int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
		}
		for(int i = 0; i < N; i++) {
			B[i] = scan.nextInt();
		}
		scan.close();
		int l = fact(N);
		list = new int[l][N];
		int []a = new int[N];
		perm(0, a, new boolean[N + 1]);

		Arrays.fill(a, 0);
		int n = 100000;
		int win = 0;
		for(int i = 0; i < n; i++) {
			int t1 = (int)(Math.random() * l);
			int t2 = (int)(Math.random() * l);
			int cnt1 = 0;
			int cnt2 = 0;
			for(int j = 0; j < N; j++) {
				int c1 = A[list[t1][j] - 1];
				int c2 = B[list[t2][j] - 1];
				if(c1 > c2) {
					cnt1 ++;
				}else if(c1 < c2) {
					cnt2 ++;
				}
			}
			if(cnt1 > cnt2) {
				win ++;
			}
		}

		double ans = (double) win / n;
		System.out.println(ans);

	}
	static void perm(int n, int[] a, boolean[] flag) {
        if(n == a.length) {
        	for(int i = 0; i < N; i++) {
        		list[index][i] = a[i];
        	}
        	index ++;
            return;
        }
        for(int i = 1; i <= a.length; i++) {
            if(flag[i]) continue;
            a[n] = i;
            flag[i] = true;
            perm(n + 1, a, flag);
            flag[i] = false;
        }
    }
	static int fact(int n) {
		if(n == 1) {
			return 1;
		}else {
			return n * fact(n - 1);
		}
	}
}
0