結果
問題 | No.133 カードゲーム |
ユーザー |
|
提出日時 | 2020-02-18 15:18:41 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 135 ms / 5,000 ms |
コード長 | 1,205 bytes |
コンパイル時間 | 2,181 ms |
コンパイル使用メモリ | 78,092 KB |
実行使用メモリ | 41,452 KB |
最終ジャッジ日時 | 2024-10-06 15:34:01 |
合計ジャッジ時間 | 5,336 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
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));}}