結果

問題 No.133 カードゲーム
ユーザー 37zigen37zigen
提出日時 2020-02-18 15:25:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 143 ms / 5,000 ms
コード長 1,117 bytes
コンパイル時間 2,175 ms
コンパイル使用メモリ 77,680 KB
実行使用メモリ 42,088 KB
最終ジャッジ日時 2024-04-16 04:09:28
合計ジャッジ時間 6,268 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
41,180 KB
testcase_01 AC 140 ms
41,328 KB
testcase_02 AC 139 ms
40,988 KB
testcase_03 AC 138 ms
41,156 KB
testcase_04 AC 140 ms
41,244 KB
testcase_05 AC 137 ms
41,396 KB
testcase_06 AC 138 ms
41,504 KB
testcase_07 AC 141 ms
41,408 KB
testcase_08 AC 143 ms
40,964 KB
testcase_09 AC 141 ms
41,372 KB
testcase_10 AC 140 ms
41,428 KB
testcase_11 AC 135 ms
41,360 KB
testcase_12 AC 137 ms
41,476 KB
testcase_13 AC 139 ms
41,232 KB
testcase_14 AC 140 ms
41,320 KB
testcase_15 AC 136 ms
42,088 KB
testcase_16 AC 131 ms
41,452 KB
testcase_17 AC 138 ms
41,496 KB
testcase_18 AC 141 ms
41,268 KB
testcase_19 AC 138 ms
41,540 KB
testcase_20 AC 138 ms
41,628 KB
testcase_21 AC 140 ms
41,496 KB
testcase_22 AC 137 ms
40,976 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 {
			int p=0;
			for(int j=0;j<o1.length;++j) {
				if(a[o1[j]]>b[j])++p;
				else if(a[o1[j]]<b[j])--p;
			}
			if(p>0)++num;
			++den;
		}while(nextPermutation(o1));
		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