結果
問題 | No.174 カードゲーム(Hard) |
ユーザー | kei |
提出日時 | 2018-09-09 11:34:17 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,281 bytes |
コンパイル時間 | 1,678 ms |
コンパイル使用メモリ | 177,556 KB |
実行使用メモリ | 167,700 KB |
最終ジャッジ日時 | 2024-07-06 21:44:11 |
合計ジャッジ時間 | 16,572 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 64 ms
167,580 KB |
testcase_01 | AC | 65 ms
167,520 KB |
testcase_02 | AC | 1,774 ms
167,636 KB |
testcase_03 | AC | 1,751 ms
167,528 KB |
testcase_04 | AC | 1,761 ms
167,468 KB |
testcase_05 | AC | 1,745 ms
167,424 KB |
testcase_06 | AC | 1,743 ms
167,464 KB |
testcase_07 | AC | 1,752 ms
167,544 KB |
testcase_08 | AC | 1,730 ms
167,700 KB |
testcase_09 | AC | 1,745 ms
167,548 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
ソースコード
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; } template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; } template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; } template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; } /* <url:https://yukicoder.me/problems/no/174> 問題文============================================================ ================================================================= 解説============================================================= ================================================================ */ typedef double ld; ld dp[1<<20][20]; vector<vector<ld>> get(vector<int>& V,ld P){ int N = (int)V.size(); sort(V.begin(),V.end()); fill(*dp,*dp+(1<<20)*20,0); dp[1<<0][0] = P; for(int i = 1; i < N;i++) dp[1<<i][i] = (1-P)/(N-1); for(int i = 0; i < (1<<N);i++){ for(int j = 0; j < N;j++){ if(dp[i][j] == 0) continue; int leafN = N - __builtin_popcount(i); if(leafN == 1){ for(int k = 0; k < N;k++){ if((i>>k)&1)continue; dp[i|(1<<k)][k] += dp[i][j]; } }else{ bool first = true; for(int k = 0; k < N;k++){ if((i>>k)&1)continue; if(first){ dp[i|(1<<k)][k] += dp[i][j]*P; first = false; }else{ dp[i|(1<<k)][k] += dp[i][j]*(1-P)/(leafN-1); } } } } } vector<vector<ld>> ret(N+1,vector<ld>(N)); for(int i = 0; i < (1<<N);i++){ for(int j = 0; j < N;j++){ int SZ = __builtin_popcount(i); ret[SZ][j] += dp[i][j]; } } return ret; } ld solve(){ ld res = 0; int N; cin >> N; ld P[2]; for(int i = 0; i < 2;i++) cin >> P[i]; vector<int> A(N),B(N); for(auto& in:A) cin >> in; for(auto& in:B) cin >> in; auto infoA = get(A,P[0]); auto infoB = get(B,P[1]); for(int i = 1; i <= N;i++){ for(int j = 0;j<N;j++){ ld selectA = infoA[i][j]; for(int k = 0;k<N;k++){ if(A[j]>B[k]){ ld selectB = infoB[i][k]; ld score = A[j]+B[k]; res += selectA*selectB*score; } } } } return res; } int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(12) << solve() << endl; return 0; }