結果

問題 No.133 カードゲーム
ユーザー norikamenorikame
提出日時 2020-04-28 05:01:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,028 bytes
コンパイル時間 2,762 ms
コンパイル使用メモリ 167,596 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-15 02:07:01
合計ジャッジ時間 3,752 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

// 総数を1000000007(素数)で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const int n_max = 4;
vi a(n_max), b(n_max);
vi an(n_max), bn(n_max);
vector<bool> au(n_max), bu(n_max);
int cnt_a = 0, cnt = 0;
void perm(int pos, int n) {
    if (pos == n*2) {
        int at = 0, bt = 0;
        rep(i, n) {
            if (an[i] > bn[i]) ++at;
            else ++bt;
        }
        if (at > bt) ++cnt_a;
        ++cnt;
        return;
    }
    if (pos < n) {
        rep(i, n) {
            if (au[i]) continue;
            au[i] = true;
            an[pos] = a[i];
            perm(pos+1, n);
            au[i] = false;
        }
    }
    else if (pos >= n) {
        rep(i, n) {
            if (bu[i]) continue;
            bu[i] = true;
            bn[pos-n] = b[i];
            perm(pos+1, n);
            bu[i] = false;
        }
    }
}

int main(){
    int n;
    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    perm(0, n);
    cout << (double)cnt_a/cnt << endl;
    return 0;
}
0