結果

問題 No.133 カードゲーム
ユーザー km_skm_jpkm_skm_jp
提出日時 2019-04-30 09:48:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,723 bytes
コンパイル時間 864 ms
コンパイル使用メモリ 101,596 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 19:37:26
合計ジャッジ時間 2,171 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <thread>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int count_win(int n, vector<int>& as, vector<int>& bs, int s, array<int, 4>& sel_a, array<int, 4>& sel_b, int w_c) {
	int ans = 0;

	if (s == n) {
		return (w_c > (n / 2)) ? 1 : 0;
	}

	FOR_LT(i_a, 0, n) {
		FOR_LT(i_b, 0, n) {
			if (find(sel_a.begin(), sel_a.end(), i_a) != sel_a.end()) continue;
			if (find(sel_b.begin(), sel_b.end(), i_b) != sel_b.end()) continue;

			bool b_w = (as[i_a] > bs[i_b]);
			int w_c_cur = w_c;
			if (b_w) {
				w_c_cur++;
			}

			sel_a[s] = i_a;
			sel_b[s] = i_b;
			ans += count_win(n, as, bs, s + 1, sel_a, sel_b, w_c_cur);
			sel_a[s] = -1;
			sel_b[s] = -1;
		}
	}

	return ans;
}

int count_all(int n) {
	int ans = 1;
	FOR_LE(i, 1, n) {
		ans *= i * i;
	}

	return ans;
}

int main()
{
	int n; cin >> n;

	vector<int> as(n);
	for (auto& a : as) {
		cin >> a;
	}
	vector<int> bs(n);
	for (auto& b : bs) {
		cin >> b;
	}

	array<int, 4> sel_a = { -1, -1, -1, -1 };
	array<int, 4> sel_b = { -1, -1, -1, -1 };
	int win_cases = count_win(n, as, bs, 0, sel_a, sel_b, 0);
	int all_cases = count_all(n);

	cout << (double)win_cases / (double)all_cases << endl;

	return 0;
}
0