結果
問題 | No.1151 チャレンジゲーム |
ユーザー | carrot46 |
提出日時 | 2020-08-07 22:49:36 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 30 ms
6,940 KB |
testcase_14 | AC | 30 ms
6,940 KB |
testcase_15 | AC | 30 ms
6,944 KB |
testcase_16 | AC | 31 ms
6,940 KB |
testcase_17 | AC | 32 ms
6,944 KB |
testcase_18 | AC | 32 ms
6,940 KB |
testcase_19 | AC | 31 ms
6,944 KB |
testcase_20 | AC | 30 ms
6,944 KB |
testcase_21 | AC | 30 ms
6,940 KB |
testcase_22 | AC | 30 ms
6,940 KB |
testcase_23 | AC | 30 ms
6,940 KB |
testcase_24 | AC | 31 ms
6,940 KB |
testcase_25 | AC | 30 ms
6,940 KB |
testcase_26 | AC | 30 ms
6,940 KB |
testcase_27 | AC | 30 ms
6,944 KB |
testcase_28 | AC | 104 ms
6,944 KB |
testcase_29 | AC | 102 ms
6,940 KB |
testcase_30 | AC | 109 ms
6,940 KB |
testcase_31 | AC | 106 ms
6,944 KB |
testcase_32 | AC | 106 ms
6,940 KB |
testcase_33 | AC | 104 ms
6,940 KB |
testcase_34 | AC | 107 ms
6,944 KB |
testcase_35 | AC | 105 ms
6,944 KB |
testcase_36 | AC | 103 ms
6,940 KB |
testcase_37 | AC | 106 ms
6,940 KB |
testcase_38 | AC | 103 ms
6,940 KB |
testcase_39 | AC | 106 ms
6,940 KB |
testcase_40 | AC | 107 ms
6,940 KB |
testcase_41 | AC | 105 ms
6,944 KB |
testcase_42 | AC | 103 ms
6,940 KB |
testcase_43 | AC | 105 ms
6,940 KB |
testcase_44 | AC | 104 ms
6,944 KB |
testcase_45 | AC | 105 ms
6,944 KB |
testcase_46 | AC | 105 ms
6,940 KB |
testcase_47 | AC | 106 ms
6,940 KB |
testcase_48 | AC | 101 ms
6,944 KB |
testcase_49 | AC | 103 ms
6,944 KB |
testcase_50 | AC | 104 ms
6,944 KB |
testcase_51 | AC | 103 ms
6,940 KB |
testcase_52 | AC | 104 ms
6,944 KB |
ソースコード
#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; }