結果

問題 No.133 カードゲーム
ユーザー nrnrknrnrk
提出日時 2022-02-17 11:52:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,405 bytes
コンパイル時間 2,838 ms
コンパイル使用メモリ 203,376 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 17:31:38
合計ジャッジ時間 4,070 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

typedef int64_t ll;
using namespace std;
#define dump(x) cout << #x << " = " << (x) << endl;
// #define dump(x) ;

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

double solve(int n, vector<int> a, vector<int> b) {
    // next_permutaion の引数はソート済みである必要がある
    std::sort(a.begin(), a.end());
    ll total = 0;
    ll a_win = 0;
    do {
        int a_up = 0;
        for (int i = 0; i < n; i++) {
            if (a.at(i) > b.at(i)) {
                a_up++;
            }
            if (a.at(i) < b.at(i)) {
                a_up--;
            }
        }
        if (a_up > 0) {
            a_win++;
        }
        total++;
        // next_permutaion の引数はソート済みである必要がある
    } while (next_permutation(a.begin(), a.end()));
    return static_cast<double>(a_win) / static_cast<double>(total);
}

// generated by oj-template v4.8.1
// (https://github.com/online-judge-tools/template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    for (int i = 0; i < n; i++) {
        cin >> b.at(i);
    }
    auto ans = solve(n, a, b);
    std::cout << ans << '\n';
    return 0;
}
0