結果

問題 No.133 カードゲーム
ユーザー t8m8⛄️t8m8⛄️
提出日時 2015-04-09 13:35:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 108 ms / 5,000 ms
コード長 1,560 bytes
コンパイル時間 3,381 ms
コンパイル使用メモリ 74,840 KB
実行使用メモリ 56,712 KB
最終ジャッジ日時 2023-09-07 09:12:36
合計ジャッジ時間 6,724 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
55,788 KB
testcase_01 AC 102 ms
56,036 KB
testcase_02 AC 100 ms
56,164 KB
testcase_03 AC 103 ms
56,340 KB
testcase_04 AC 105 ms
56,308 KB
testcase_05 AC 103 ms
56,140 KB
testcase_06 AC 103 ms
56,328 KB
testcase_07 AC 103 ms
56,000 KB
testcase_08 AC 105 ms
56,300 KB
testcase_09 AC 105 ms
56,100 KB
testcase_10 AC 100 ms
55,856 KB
testcase_11 AC 99 ms
56,172 KB
testcase_12 AC 105 ms
56,104 KB
testcase_13 AC 104 ms
55,964 KB
testcase_14 AC 105 ms
56,040 KB
testcase_15 AC 104 ms
56,020 KB
testcase_16 AC 108 ms
56,712 KB
testcase_17 AC 107 ms
56,088 KB
testcase_18 AC 101 ms
56,048 KB
testcase_19 AC 102 ms
56,152 KB
testcase_20 AC 106 ms
55,908 KB
testcase_21 AC 104 ms
55,968 KB
testcase_22 AC 104 ms
55,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//No.133 カードゲーム

import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class No133 {
    
    static final Scanner in = new Scanner(System.in);
    static final PrintWriter out = new PrintWriter(System.out,false);

    static void solve() {
        int n = in.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i=0; i<n; i++) a[i] = in.nextInt();
        for (int i=0; i<n; i++) b[i] = in.nextInt();
        int win = 0,game = 0;
        sort(a);
        do {
            int cnt = 0;
            for (int i=0; i<n; i++) {
                if (a[i] - b[i] > 0) cnt++;
            }
            if (cnt > n/2) win++;
            game++;
        }while(nextPermutation(a));
        out.println((double)win/game);
    }

    static boolean nextPermutation(int[] a) {
        int n = a.length, i, j;
        for (i=n-2; i>=0 && a[i]>=a[i+1]; i--);
        if (i == -1) return false;
        for (j=i+1; j<n && a[i]<a[j]; j++);
        int temp = a[i]; a[i] = a[j-1]; a[j-1] = temp;
        for (int l=i+1, r=n-1; l<r; l++,r--) {
            temp = a[l]; a[l] = a[r]; a[r] = temp;
        }
        return true;
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        solve();
        out.flush();

        long end = System.currentTimeMillis();
        //trace(end-start + "ms");
        in.close();
        out.close();
    }

    static void trace(Object... o) { System.out.println(deepToString(o));}
}
0