Submission #1690819


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;
long double p, q;
int a[35][35], win[35], lose[35];
vector<pair<int, int>> rk;
long double dp[35][35], ac_power[35], wa_power[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;
}


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);
    ac_power[0] = 1.0;
    wa_power[0] = 1.0;
    long double ac = p / q;
    long double wa = 1 - ac;
    rep2(i, 1, n + 1) {
        ac_power[i] = ac_power[i - 1] * ac;
        wa_power[i] = wa_power[i - 1] * wa;
    }
    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) {
                    long double ac_win = (long double)com[win[idx]][l] * ac_power[l] * wa_power[win[idx] - l];
                    long double wa_win = (long double)com[lose[idx]][j - l] * wa_power[j - l] * ac_power[lose[idx] - (j - l)];
                    dp[i + 1][j] += dp[i][j] * ac_win * wa_win;
                    continue;
                }
                rep2(k, j + 1, n) {
                    long double ac_win = (long double)com[win[idx]][l] * ac_power[l] * wa_power[win[idx] - l];
                    long double wa_win = (long double)com[lose[idx]][j - l] * wa_power[j - l] * ac_power[lose[idx] - (j - l)];
                    dp[i + 1][j] += dp[i][k] * ac_win * wa_win;
                }
                if (rk[i].se > rk[i - 1].se) {
                    long double ac_win = (long double)com[win[idx]][l] * ac_power[l] * wa_power[win[idx] - l];
                    long double wa_win = (long double)com[lose[idx]][j - l] * wa_power[j - l] * ac_power[lose[idx] - (j - l)];
                    dp[i + 1][j] += dp[i][j] * ac_win * wa_win;
                }
            }
        }
    }
    long 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 4146 Byte
Status WA
Exec Time 3 ms
Memory 384 KB

Judge Result

Set Name All
Score / Max Score 0 / 600
Status
AC × 25
WA × 18
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 1 ms 256 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 AC 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 1 ms 256 KB
20_random_01 AC 1 ms 256 KB
20_random_02 WA 1 ms 256 KB
20_random_03 WA 1 ms 256 KB
20_random_04 AC 1 ms 256 KB
20_random_05 WA 1 ms 256 KB
20_random_06 AC 1 ms 256 KB
20_random_07 WA 1 ms 256 KB
20_random_08 AC 1 ms 256 KB
20_random_09 WA 1 ms 256 KB
20_random_10 WA 1 ms 256 KB
20_random_11 AC 1 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 1 ms 256 KB
20_random_17 WA 1 ms 256 KB
20_random_18 AC 1 ms 256 KB
20_random_19 WA 1 ms 256 KB
30_manual_13 WA 3 ms 384 KB
30_manual_14 WA 2 ms 256 KB
30_manual_15 WA 1 ms 256 KB
30_manual_16 AC 2 ms 256 KB
30_manual_17 AC 2 ms 256 KB
30_manual_18 WA 2 ms 256 KB
30_manual_19 WA 2 ms 256 KB