Submission #1690738


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n;
string s;
double p, q;
int a[35][35], win[35], lose[35];
vector<pair<int, int>> rk;
double dp[35][35];

bool comp(pair<int, int> p1, pair<int, int> p2) {
    if (p1.fi > p2.fi) return true;
    else if (p1.fi == p2.fi) return p1.se < p2.se;
    else return false;
}

vector<vector<long long>> p_triangle(long long n) {
    vector<vector<long long>> ret(n + 1, vector<long long>(n + 1, 0));
    ret[0][0] = 1;
    for (int i = 1; i < n + 1; i++) {
        for (int j = 0 ; j < i + 1; j++) {
            if (j == 0) ret[i][j] = ret[i - 1][j];
            else if (j == i) ret[i][j] = ret[i - 1][j - 1];
            else ret[i][j] = ret[i - 1][j - 1] + ret[i - 1][j];
        }
    }
    return ret;
}

double power(double n, int k){
    if (n == 0) return 0.0;
    if (k == 0) return 1.0;
    else if (k % 2 == 0){
        double tmp = power(n, k / 2);
        return tmp * tmp;
    }
    else return power(n, k - 1) * n;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> s;
    p = s[0] - '0';
    q = s[2] - '0';
    rep(i, n) {
        int cnt = 0;
        rep(j, n) {
            cin >> a[i][j];
            if (a[i][j] == 1) cnt++;
        }
        win[i] = cnt;
        lose[i] = n - 1 - cnt;
        rk.push_back({cnt, i});
    }
    sort(all(rk), comp);
    vector<vector<long long>> com = p_triangle(35);
    double ac = p / q;
    double wa = 1 - ac;
    rep(j, n) dp[0][j] = 1.0;
    rep(i, n) {
        int idx = rk[i].se;
        rep(j, n) {
            rep(l, win[idx] + 1) {
                if (j < l || lose[idx] + l < j) continue;
                if (i == 0) {
                    double ac_win = com[win[idx]][l] * power(ac, l) * power(wa, win[idx] - l);
                    double wa_win = com[lose[idx]][j - l] * power(wa, j - l) * power(ac, lose[idx] - (j - l));
                    dp[i + 1][j] += dp[i][j] * ac_win * wa_win;
                    continue;
                }
                rep2(k, j + 1, n) {
                    double ac_win = com[win[idx]][l] * power(ac, l) * power(wa, win[idx] - l);
                    double wa_win = com[lose[idx]][j - l] * power(wa, j - l) * power(ac, lose[idx] - (j - l));
                    dp[i + 1][j] += dp[i][k] * ac_win * wa_win;
                }
                if (rk[i].se > rk[i - 1].se) {
                    double ac_win = com[win[idx]][l] * power(ac, l) * power(wa, win[idx] - l);
                    double wa_win = com[lose[idx]][j - l] * power(wa, j - l) * power(ac, lose[idx] - (j - l));
                    dp[i + 1][j] += dp[i][j] * ac_win * wa_win;
                }
            }
        }
    }
    double ans = 0.0;
    rep(j, n) ans += dp[n][j];
    cout << fixed << setprecision(20) << ans << endl;
}

Submission Info

Submission Time
Task C - 天下一プログラマーコンテスト1999
User roto_37
Language C++14 (GCC 5.4.1)
Score 0
Code Size 4058 Byte
Status WA
Exec Time 7 ms
Memory 384 KB

Judge Result

Set Name All
Score / Max Score 0 / 600
Status
AC × 24
WA × 19
Set Name Test Cases
All 00_sample_01, 00_sample_02, 00_sample_03, 00_sample_04, 02_manual_01, 02_manual_02, 02_manual_03, 02_manual_04, 02_manual_05, 02_manual_06, 02_manual_07, 02_manual_08, 02_manual_09, 02_manual_10, 02_manual_11, 02_manual_12, 20_random_00, 20_random_01, 20_random_02, 20_random_03, 20_random_04, 20_random_05, 20_random_06, 20_random_07, 20_random_08, 20_random_09, 20_random_10, 20_random_11, 20_random_12, 20_random_13, 20_random_14, 20_random_15, 20_random_16, 20_random_17, 20_random_18, 20_random_19, 30_manual_13, 30_manual_14, 30_manual_15, 30_manual_16, 30_manual_17, 30_manual_18, 30_manual_19
Case Name Status Exec Time Memory
00_sample_01 AC 2 ms 384 KB
00_sample_02 AC 1 ms 256 KB
00_sample_03 AC 1 ms 256 KB
00_sample_04 AC 1 ms 256 KB
02_manual_01 AC 1 ms 256 KB
02_manual_02 AC 1 ms 256 KB
02_manual_03 AC 1 ms 256 KB
02_manual_04 AC 1 ms 256 KB
02_manual_05 AC 1 ms 256 KB
02_manual_06 AC 1 ms 256 KB
02_manual_07 WA 1 ms 256 KB
02_manual_08 WA 1 ms 256 KB
02_manual_09 WA 1 ms 256 KB
02_manual_10 WA 1 ms 256 KB
02_manual_11 WA 1 ms 256 KB
02_manual_12 WA 1 ms 256 KB
20_random_00 AC 2 ms 256 KB
20_random_01 AC 2 ms 256 KB
20_random_02 AC 1 ms 256 KB
20_random_03 WA 2 ms 256 KB
20_random_04 AC 2 ms 256 KB
20_random_05 WA 2 ms 256 KB
20_random_06 AC 2 ms 256 KB
20_random_07 WA 1 ms 256 KB
20_random_08 AC 2 ms 256 KB
20_random_09 WA 2 ms 256 KB
20_random_10 WA 2 ms 256 KB
20_random_11 AC 2 ms 256 KB
20_random_12 AC 1 ms 256 KB
20_random_13 AC 1 ms 256 KB
20_random_14 AC 1 ms 256 KB
20_random_15 AC 1 ms 256 KB
20_random_16 AC 2 ms 256 KB
20_random_17 WA 2 ms 256 KB
20_random_18 AC 2 ms 256 KB
20_random_19 WA 2 ms 256 KB
30_manual_13 WA 5 ms 256 KB
30_manual_14 WA 5 ms 256 KB
30_manual_15 WA 2 ms 256 KB
30_manual_16 AC 5 ms 256 KB
30_manual_17 WA 4 ms 256 KB
30_manual_18 WA 7 ms 256 KB
30_manual_19 WA 7 ms 256 KB