結果
問題 | No.174 カードゲーム(Hard) |
ユーザー | nsd_fb |
提出日時 | 2015-03-27 00:52:06 |
言語 | C++11 (gcc 13.3.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,859 bytes |
コンパイル時間 | 1,597 ms |
コンパイル使用メモリ | 173,708 KB |
実行使用メモリ | 25,856 KB |
最終ジャッジ日時 | 2024-06-29 01:22:19 |
合計ジャッジ時間 | 18,885 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 TLE * 8 |
ソースコード
#include <bits/stdc++.h> #include <sys/time.h> #ifdef LOCAL #include "dump.hpp" #else #define dump(...) #endif using namespace std; #define REP(i, a, b) for(int i = (a); i < int(b); ++i) #define rep(i, n) REP(i, 0, n) #define ALL(x) begin(x), end(x) template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; } template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; } vector<vector<double>> calc(int n, double p) { const double q = 1.0 - p; vector<vector<double>> res(n, vector<double>(n, 0)); map<int, double> dp; dp[(1 << n) - 1] = 1.0; for(int i = 0; i < n; ++i) { const int num = n - i; map<int, double> next_dp; double sum = 0.0; for(const auto &e : dp) { const auto card = e.first; const auto cp = e.second; bool first = true; for(int j = 0; j < n; ++j) { if((card >> j) & 1) { double np; if(num == 1) { np = cp; } else if(first) { np = cp * p; } else { np = cp * q / (num - 1); } first = false; res[j][i] += np; next_dp[card ^ (1 << j)] += np; } } sum += cp; } assert(abs(sum - 1.0) < 1e-8); dp = move(next_dp); } return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(10); int n; double pa, pb; cin >> n >> pa >> pb; vector<int> a(n); vector<int> b(n); for(auto &e : a) cin >> e; for(auto &e : b) cin >> e; sort(begin(a), end(a)); sort(begin(b), end(b)); const auto pa_card = calc(n, pa); const auto pb_card = calc(n, pb); dump(pa_card, pb_card); double ans = 0.0; for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) { if(a[i] < b[j]) continue; for(int k = 0; k < n; ++k) { ans += (a[i] + b[j]) * pa_card[i][k] * pb_card[j][k]; } } } cout << ans << endl; return EXIT_SUCCESS; }