結果
| 問題 |
No.1151 チャレンジゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-07 23:20:34 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 2,000 ms |
| コード長 | 2,577 bytes |
| コンパイル時間 | 2,288 ms |
| コンパイル使用メモリ | 196,660 KB |
| 最終ジャッジ日時 | 2025-01-12 18:26:30 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 50 |
ソースコード
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;
auto solve(int n, const vector<int> & a) {
vector<int> pow_3(n + 1);
pow_3[0] = 1;
REP (i, n) {
pow_3[i + 1] = pow_3[i] * 3;
}
vector<array<double, 2> > dp(pow_3[n]);
REP_R (state, pow_3[n]) {
int available = 0;
int score = 0;
{ // unpack
int s = state;
REP (i, n) {
if (s % 3 == 0) {
available |= 1 << i;
} else if (s % 3 == 1) {
score += a[i];
} else {
score -= a[i];
}
s /= 3;
}
}
if (not available) {
dp[state][false] = score > 0;
dp[state][true] = score <= 0;
} else {
REP (turn, 2) {
REP (i, n) if (available & (1 << i)) {
double prob = 1;
REP (j, n) if (available & (1 << j)) {
double p = 1.0 / a[i];
double q = 1.0 / a[j];
if (a[i] == 1) {
double x = 1 - dp[state + (turn + 1) * pow_3[i]][not turn];
prob = min(prob, x);
} else if (a[j] == 1) {
double x = p * (1 - dp[state + (turn + 1) * pow_3[i]][not turn]);
double y = (1 - p) * dp[state + (not turn + 1) * pow_3[j]][turn];
prob = min(prob, x + y);
} else {
double x = p * (1 - dp[state + (turn + 1) * pow_3[i]][not turn]);
double y = (1 - p) * q * dp[state + (not turn + 1) * pow_3[j]][turn];
double r = (1 - p) * (1 - q);
prob = min(prob, (x + y) / (1 - r));
}
}
dp[state][turn] = max(dp[state][turn], prob);
}
}
}
}
return dp[0][false];
}
int main() {
int n; cin >> n;
vector<int> a(n);
REP (i, n) {
cin >> a[i];
}
auto ans = solve(n, a);
cout << setprecision(18) << ans << endl;
return 0;
}