結果

問題 No.1151 チャレンジゲーム
ユーザー carrot46carrot46
提出日時 2020-08-07 22:49:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 3,028 bytes
コンパイル時間 1,841 ms
コンパイル使用メモリ 177,640 KB
実行使用メモリ 5,932 KB
最終ジャッジ日時 2023-10-25 03:41:57
合計ジャッジ時間 6,596 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 32 ms
4,348 KB
testcase_14 AC 32 ms
4,348 KB
testcase_15 AC 32 ms
4,348 KB
testcase_16 AC 32 ms
4,348 KB
testcase_17 AC 32 ms
4,348 KB
testcase_18 AC 32 ms
4,348 KB
testcase_19 AC 32 ms
4,348 KB
testcase_20 AC 31 ms
4,348 KB
testcase_21 AC 31 ms
4,348 KB
testcase_22 AC 32 ms
4,348 KB
testcase_23 AC 31 ms
4,348 KB
testcase_24 AC 31 ms
4,348 KB
testcase_25 AC 31 ms
4,348 KB
testcase_26 AC 32 ms
4,348 KB
testcase_27 AC 31 ms
4,348 KB
testcase_28 AC 112 ms
5,932 KB
testcase_29 AC 111 ms
5,932 KB
testcase_30 AC 110 ms
5,932 KB
testcase_31 AC 110 ms
5,932 KB
testcase_32 AC 110 ms
5,932 KB
testcase_33 AC 110 ms
5,932 KB
testcase_34 AC 110 ms
5,932 KB
testcase_35 AC 109 ms
5,932 KB
testcase_36 AC 111 ms
5,932 KB
testcase_37 AC 109 ms
5,932 KB
testcase_38 AC 110 ms
5,932 KB
testcase_39 AC 109 ms
5,932 KB
testcase_40 AC 111 ms
5,932 KB
testcase_41 AC 111 ms
5,932 KB
testcase_42 AC 111 ms
5,932 KB
testcase_43 AC 112 ms
5,932 KB
testcase_44 AC 112 ms
5,932 KB
testcase_45 AC 112 ms
5,932 KB
testcase_46 AC 111 ms
5,932 KB
testcase_47 AC 112 ms
5,932 KB
testcase_48 AC 109 ms
5,932 KB
testcase_49 AC 111 ms
5,932 KB
testcase_50 AC 110 ms
5,932 KB
testcase_51 AC 109 ms
5,932 KB
testcase_52 AC 111 ms
5,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0