結果
| 問題 | No.133 カードゲーム | 
| コンテスト | |
| ユーザー |  km_skm_jp | 
| 提出日時 | 2019-04-30 09:48:49 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 1,723 bytes | 
| コンパイル時間 | 2,865 ms | 
| コンパイル使用メモリ | 100,788 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-12-28 01:42:23 | 
| 合計ジャッジ時間 | 2,123 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 19 | 
ソースコード
#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;
}
            
            
            
        