結果

問題 No.133 カードゲーム
ユーザー 37zigen
提出日時 2020-02-18 15:25:48
言語 Java
(openjdk 23)
結果
AC  
実行時間 122 ms / 5,000 ms
コード長 1,117 bytes
コンパイル時間 2,213 ms
コンパイル使用メモリ 77,312 KB
実行使用メモリ 41,400 KB
最終ジャッジ日時 2024-10-06 15:34:47
合計ジャッジ時間 5,249 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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