結果

問題 No.133 カードゲーム
ユーザー ms ms
提出日時 2020-04-14 20:26:37
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,358 bytes
コンパイル時間 2,034 ms
コンパイル使用メモリ 177,868 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-01 18:08:27
合計ジャッジ時間 2,478 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;

void ERROR(int num) { printf("ERROR%d!\n",num); }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};

int N;
vector<int> A, B;
vector<vector<int>> PERM1, PERM2;

int CMP(int a, int b){
	int cntA = 0, cntB = 0;
	rep(i,N){
		int numA = PERM1[a][i];
		int numB = PERM2[b][i];
		if(numA > numB) cntA++;
		else cntB++;
	}

	return (cntA > cntB) ? 1:0;
}

void PRINT(vector<int> P, int num){
	cout  << "SHOW" << num << ": ";
	rep(i,P.size()){
		cout << P[i] << " "; 
	}
	cout << endl;
}

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

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

	do{
		PERM1.pb(A);
		//PRINT(A,1);
	}while(next_permutation(A.begin(),A.end()));

	do{
		PERM2.pb(B);
		//PRINT(B,2);
	}while(next_permutation(B.begin(),B.end()));


	int cnt = 0;
	rep(a,PERM1.size()){
		rep(b,PERM2.size()){
			cnt += CMP(a,b);
		}
	}
	double P = (double)(cnt) / ((double)(PERM1.size()) * (double)(PERM2.size()));
	cout << P << endl;
}
0