結果

問題 No.133 カードゲーム
ユーザー crazybbb3crazybbb3
提出日時 2017-01-29 23:23:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 46 ms / 5,000 ms
コード長 2,497 bytes
コンパイル時間 3,228 ms
コンパイル使用メモリ 73,852 KB
実行使用メモリ 33,944 KB
最終ジャッジ日時 2023-09-07 09:30:37
合計ジャッジ時間 4,202 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
33,716 KB
testcase_01 AC 41 ms
33,852 KB
testcase_02 AC 41 ms
33,724 KB
testcase_03 AC 42 ms
33,612 KB
testcase_04 AC 44 ms
33,624 KB
testcase_05 AC 42 ms
33,632 KB
testcase_06 AC 42 ms
33,924 KB
testcase_07 AC 46 ms
33,516 KB
testcase_08 AC 43 ms
33,628 KB
testcase_09 AC 42 ms
33,724 KB
testcase_10 AC 42 ms
33,852 KB
testcase_11 AC 43 ms
33,624 KB
testcase_12 AC 42 ms
33,652 KB
testcase_13 AC 42 ms
33,924 KB
testcase_14 AC 43 ms
33,652 KB
testcase_15 AC 41 ms
33,632 KB
testcase_16 AC 41 ms
33,708 KB
testcase_17 AC 41 ms
33,612 KB
testcase_18 AC 42 ms
33,664 KB
testcase_19 AC 42 ms
33,772 KB
testcase_20 AC 42 ms
33,576 KB
testcase_21 AC 41 ms
33,944 KB
testcase_22 AC 41 ms
33,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    void solve() throws IOException {
        int n = ni();
        int[] a = nia(n);
        int[] b = nia(n);

        Arrays.sort(a);
        double ans = 0;
        do {
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                if (a[i] > b[i]) cnt++;
            }
            if (cnt > n - cnt) ans++;
        } while (nextPermutation(a));

        for (int i = 1; i <= n; i++) {
            ans /= i;
        }

        out.println(ans);
    }

    boolean nextPermutation(int[] a) {
        int n = a.length;

        int i = n - 1;
        while (i > 0 && a[i - 1] >= a[i]) i--;
        if (i <= 0) return false;

        int j = n - 1;
        while (a[j] <= a[i - 1]) j--;
        swap(a, i - 1, j);

        int k = n - 1;
        while (i < k) swap(a, i++, k--);

        return true;
    }

    void swap(int[] a, int i, int j) {
        int tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}
0