結果
| 問題 |
No.1151 チャレンジゲーム
|
| コンテスト | |
| ユーザー |
carrot46
|
| 提出日時 | 2020-08-07 22:49:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 109 ms / 2,000 ms |
| コード長 | 3,028 bytes |
| コンパイル時間 | 1,900 ms |
| コンパイル使用メモリ | 178,552 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-24 23:11:07 |
| 合計ジャッジ時間 | 5,992 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 50 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll N,M,H,W,Q,K,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);
template<class T> bool chmin(T &a, const T &b){
if(a > b) {a = b; return true;}
else return false;
}
template<class T> bool chmax(T &a, const T &b){
if(a < b) {a = b; return true;}
else return false;
}
ll encode(vec &v){
ll res = 0;
Rrep(i,N){
(res *= 3)+=v[i];
}
return res;
}
void decode(vec &v, vec &zero, ll code){
rep(i,N){
v.push_back(code%3);
if(code%3 == 0) zero.push_back(i);
code/=3;
}
}
void check(vec &state, long double p){
rep(i,N) cout<<(state[i] ? (state[i] == 1 ? 'n' : 'k') : '0')<<' ';
cout<<p<<endl;
}
bool debug = false;
long double dfs(vector<vector<long double> > &dp, vec &a, int turn, ll code){
if(dp[turn][code] > -0.5) return dp[turn][code];
vec state(0), zero(0);
decode(state, zero, code);
if(zero.empty()){
ll score = 0;
rep(i,N) score += (state[i] == 1 ? a[i] : -a[i]);
//if(debug) check(state, (long double)score);
return dp[turn][code] = (score > 0 ? 1 : 0);
}
if(turn) dp[turn][code] = 1.0;
for(int i : zero){
long double memo = 1 - turn;
for(int j : zero){
long double temp = 0;
if(i == j){
long double p = 1.0 / (2.0 - 1.0 / a[i]);
if(turn) p = 1.0 - p;
state[i] = 1;
temp += p * dfs(dp, a, 1, encode(state));
state[i] = 2;
temp += (1.0 - p) * dfs(dp, a, 0, encode(state));
state[i] = 0;
}else{
long double p = 1.0 / (1.0 + ((long double)a[i] - 1.0) / a[j]);
state[i] = 1 + turn;
temp += p * dfs(dp, a, 1 - turn, encode(state));
state[i] = 0;
state[j] = 2 - turn;
temp += (1.0 - p) * dfs(dp, a, turn, encode(state));
state[j] = 0;
}
if(code == 0 && debug) cout<<i<<' '<<j<<' '<<temp<<endl;
if(turn) chmax(memo, temp);
else chmin(memo, temp);
}
if(turn) chmin(dp[turn][code], memo);
else chmax(dp[turn][code], memo);
}
/*
if(debug) {
cout<<(turn ? "kiri" : "null")<<" ";
check(state, dp[turn][code]);
}
*/
return dp[turn][code];
}
int main() {
cin>>N;
vec a(N);
rep(i,N) cin>>a[i];
ll n3 = 1;
rep(i,N) n3 *= 3;
vector<vector<long double> > dp(2, vector<long double>(n3, -1));
dfs(dp, a, 0, 0);
cout<<fixed<<setprecision(10)<<dp[0][0]<<endl;
}
carrot46