結果

問題 No.133 カードゲーム
ユーザー 37zigen37zigen
提出日時 2020-02-18 15:18:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 1,205 bytes
コンパイル時間 2,229 ms
コンパイル使用メモリ 77,744 KB
実行使用メモリ 41,728 KB
最終ジャッジ日時 2024-04-16 04:09:15
合計ジャッジ時間 6,327 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
41,432 KB
testcase_01 AC 115 ms
40,284 KB
testcase_02 AC 131 ms
41,424 KB
testcase_03 AC 129 ms
41,332 KB
testcase_04 AC 130 ms
41,284 KB
testcase_05 AC 120 ms
40,212 KB
testcase_06 AC 117 ms
40,420 KB
testcase_07 AC 118 ms
40,220 KB
testcase_08 AC 131 ms
41,528 KB
testcase_09 AC 129 ms
41,520 KB
testcase_10 AC 131 ms
41,376 KB
testcase_11 AC 132 ms
41,604 KB
testcase_12 AC 130 ms
41,700 KB
testcase_13 AC 128 ms
41,060 KB
testcase_14 AC 128 ms
41,444 KB
testcase_15 AC 129 ms
41,728 KB
testcase_16 AC 133 ms
41,168 KB
testcase_17 AC 125 ms
41,108 KB
testcase_18 AC 117 ms
40,204 KB
testcase_19 AC 134 ms
41,684 KB
testcase_20 AC 132 ms
41,224 KB
testcase_21 AC 132 ms
41,612 KB
testcase_22 AC 132 ms
41,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] o1=new int[N];
		int[] o2=new int[N];
		for(int i=0;i<N;++i) {
			o1[i]=i;
			o2[i]=i;
		}
		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();
		}
		double num=0;
		double den=0;
		do {
			for(int i=0;i<N;++i) o1[i]=i;
			do {
				int p=0;
				for(int j=0;j<o1.length;++j) {
					if(a[o1[j]]>b[o2[j]])++p;
					else if(a[o1[j]]<b[o2[j]])--p;
				}
				if(p>0)++num;
				++den;
			}while(nextPermutation(o1));
		}while(nextPermutation(o2));
		System.out.println(num/den);
	}
	
	boolean nextPermutation(int[] o) {
		int s=o.length-1;
		while(s>0&&o[s-1]>o[s]) --s;
		if(s==0)return false;
		int p=s;
		while(p+1<o.length&&o[s-1]<o[p+1])++p;
		o[s-1]^=o[p];o[p]^=o[s-1];o[s-1]^=o[p];
		int t=o.length-1;
		while(s<t) {
			o[s]^=o[t];o[t]^=o[s];o[s]^=o[t];
			++s;--t;
		}
		return true;
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}
0