結果

問題 No.133 カードゲーム
ユーザー ぴろずぴろず
提出日時 2015-01-23 08:59:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 5,000 ms
コード長 1,029 bytes
コンパイル時間 2,661 ms
コンパイル使用メモリ 79,144 KB
実行使用メモリ 55,952 KB
最終ジャッジ日時 2023-09-07 09:10:12
合計ジャッジ時間 6,896 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,756 KB
testcase_01 AC 131 ms
55,284 KB
testcase_02 AC 126 ms
55,828 KB
testcase_03 AC 126 ms
55,724 KB
testcase_04 AC 126 ms
53,748 KB
testcase_05 AC 124 ms
55,708 KB
testcase_06 AC 125 ms
55,576 KB
testcase_07 AC 126 ms
55,568 KB
testcase_08 AC 127 ms
55,844 KB
testcase_09 AC 128 ms
55,684 KB
testcase_10 AC 125 ms
55,740 KB
testcase_11 AC 126 ms
55,692 KB
testcase_12 AC 126 ms
55,544 KB
testcase_13 AC 123 ms
55,616 KB
testcase_14 AC 124 ms
55,952 KB
testcase_15 AC 126 ms
55,692 KB
testcase_16 AC 128 ms
55,676 KB
testcase_17 AC 126 ms
55,648 KB
testcase_18 AC 126 ms
55,524 KB
testcase_19 AC 126 ms
55,432 KB
testcase_20 AC 128 ms
53,340 KB
testcase_21 AC 132 ms
55,844 KB
testcase_22 AC 128 ms
55,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no133;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] 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();
		}
		int[] pa = new int[n];
		for(int i=0;i<n;i++) {
			pa[i] = i;
		}
		double ans = 0;
		do {
			int wins = 0;
			for(int i=0;i<n;i++) {
				if(a[pa[i]] > b[i]) {
					wins++;
				}
			}
			if (wins > n / 2) {
				ans++;
			}
		} while(nextPermutation(pa));
		for(int i=1;i<=n;i++) {
			ans /= i;
		}
		System.out.println(ans);

	}
	static boolean nextPermutation(int[] p) {
		for(int a=p.length-2;a>=0;--a) {
			if(p[a]<p[a+1]) {
				for(int b=p.length-1;;--b) {
					if(p[b]>p[a]) {
						int t = p[a];
						p[a] = p[b];
						p[b] = t;
						for(++a, b=p.length-1;a<b;++a,--b) {
							t = p[a];
							p[a] = p[b];
							p[b] = t;
						}
						return true;
					}
				}
			}
		}
		return false;
	}
}
0