結果
問題 | No.1151 チャレンジゲーム |
ユーザー |
|
提出日時 | 2020-08-13 18:23:37 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 136 ms / 2,000 ms |
コード長 | 1,499 bytes |
コンパイル時間 | 1,565 ms |
コンパイル使用メモリ | 172,772 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-09 19:26:51 |
合計ジャッジ時間 | 6,978 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
//#include <bits/stdc++.h>using namespace std;#define fi first#define se second#define all(x) x.begin(), x.end()#define lch (o << 1)#define rch (o << 1 | 1)typedef double db;typedef long long ll;typedef unsigned int ui;typedef pair<int, int> pint;typedef tuple<int, int, int> tint;const int N = 10 + 2;const int S = (59049) + 5;const int INF = 0x3f3f3f3f;const ll INF_LL = 0x3f3f3f3f3f3f3f3f;double f[S][2];bool vst[S][2];int a[N];int n;double DFS(int s, int op) {if (vst[s][op]) return f[s][op];vst[s][op] = 1;vector<int> vec, pos;for (int i = 0, x = s; i < n; i++) {vec.push_back(x % 3);if (x % 3 == 0) pos.push_back(i);x /= 3;}if (pos.empty()) {int sum1 = 0, sum2 = 0;for (int i = 0; i < n; i++) {if (vec[i] == 1) sum1 += a[i];if (vec[i] == 2) sum2 += a[i];}if (op == 0) f[s][op] = sum1 > sum2;if (op == 1) f[s][op] = sum2 >= sum1;} else {for (auto i: pos) {double minf = 1;for (auto j: pos) {// get p(i, j)int s1 = s + pow(3, i) * (op + 1);int s2 = s + pow(3, j) * ((op ^ 1) + 1);double pij = (1.0 / a[i]) * (1 - DFS(s1, op ^ 1)) + (1 - 1.0 / a[i]) * (1.0 / a[j]) * DFS(s2, op);pij /= 1 - (1 - 1.0 / a[i]) * (1 - 1.0 / a[j]);minf = min(minf, pij);}f[s][op] = max(f[s][op], minf);}}return f[s][op];}int main() {ios::sync_with_stdio(0);cin >> n;for (int i = 0; i < n; i++)cin >> a[i];cout << fixed << setprecision(10) << DFS(0, 0) << endl;return 0;}