結果

問題 No.133 カードゲーム
ユーザー noritakenoritake
提出日時 2020-09-09 09:46:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,686 bytes
コンパイル時間 2,066 ms
コンパイル使用メモリ 177,016 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-21 03:20:03
合計ジャッジ時間 3,401 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include <atcoder/all> // NOTE: AtCoderライブラリ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
// using namespace atcoder; // NOTE: AtCoderライブラリ
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef pair<int, int> pii;
// #define INF __INT32_MAX__
#define INF 1e9
#define LINF __LONG_LONG_MAX__

int fac(int n) {
    if (n <= 1) return 1;
    return n * fac(n - 1);
}

int main() {
    int N; cin >> N;
    vi A(N);
    rep(i, N) cin >> A[i];
    vi B(N);
    rep(i, N) cin >> B[i];

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    vector<vi> ap;
    do {
        vi tmp;
        rep(i, N) {
            tmp.push_back(A[i]);
        }
        ap.push_back(tmp);
    } while (next_permutation(A.begin(), A.end()));

    vector<vi> bp;
    do {
        vi tmp;
        rep(i, N) {
            tmp.push_back(B[i]);
        }
        bp.push_back(tmp);
    } while (next_permutation(B.begin(), B.end()));

    int awin = 0;
    for (int i = 0; i < ap.size(); i++) {
        vi app = ap[i];
        for (int j = 0; j < bp.size(); j++) {
            vi bpp = bp[j];

            int acnt = 0;
            int bcnt = 0;
            for (int k = 0; k < N; k++) {
                if (app[k] < bpp[k]) {
                    bcnt++;
                } else if (app[k] > bpp[k]) {
                    acnt++;
                }
            }

            if (acnt > bcnt) awin++;
        }
    }

    ld res = (1.0 * awin) / (1.0 * fac(N) * fac(N));

    cout << fixed << setprecision(10) << res << endl;
}
0