Submission #1687763


Source Code Expand

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N;
	string s;
	cin >> s;
	long double p;
	long double a = 0;
	long double b = 0;
	bool flag = true;
	for (auto i : s) {
		if (i == '/') {
			flag = false;
		}
		else if (flag) {
			a *= 10;
			a += i - '0';
		}
		else {
			b *= 10;
			b += i - '0';
		}
	}
	p = a / b;
	vector<vector<int>>battle(N);
	vector<pair<int,int>>c_win(N);
	for (int i = 0; i < N; i++) {
		c_win[i].second = N - i;
		for (int j = 0; j < N; j++) {
			cin >> K;
			if (i != j) {
				battle[i].push_back(K);
			}
			if (K) {
				c_win[i].first++;
			}
		}
	}
	vector<int>order(N);
	sort(c_win.begin(), c_win.end());
	reverse(c_win.begin(), c_win.end());
	for (int i = 0; i < N; i++) {
		order[N - c_win[i].second] = i;
	}
	vector<vector<vector<long double>>>dp(N, vector<vector<long double>>(N + 1, vector<long double>(N + 1)));
	for (int i = 0; i < N; i++) {
		dp[i][0][0] = 1;
		for (int j = 1; j < N; j++) {
			for (int k = 0; k < j; k++) {
				if (battle[i][j - 1]) {
					dp[i][j][k] += dp[i][j - 1][k] * ((long double)1 - p);
					dp[i][j][k + 1] += dp[i][j - 1][k] * p;
				}
				else {
					dp[i][j][k + 1] += dp[i][j - 1][k] * ((long double)1 - p);
					dp[i][j][k] += dp[i][j - 1][k] * p;
				}
			}
		}
	}
	long double ans = 1;
	for (int i = 0; i < N; i++) {
		for (int j = i+1; j < N; j++) {
			int fst, snd;
			if (order[i] > order[j]) {
				fst = j;
				snd = i;
			}
			else {
				fst = i;
				snd = j;
			}
			long double box = 0;
			long double sum = 0;
			if (fst == i) {
				for (int k = 0; k < N; k++) {
					sum += dp[snd][N - 1][k];
					box += dp[fst][N - 1][k] * sum;
				}
			}
			else {
				for (int k = 0; k < N; k++) {
					box += dp[fst][N - 1][k] * sum;
					sum += dp[snd][N - 1][k];
				}
			}
			ans *= box;
		}
	}
	cout << setprecision(20) << ans << endl;
	return 0;
}

Submission Info

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

Judge Result

Set Name All
Score / Max Score 0 / 600
Status
AC × 26
WA × 17
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 WA 1 ms 256 KB
02_manual_01 AC 1 ms 256 KB
02_manual_02 AC 1 ms 256 KB
02_manual_03 WA 1 ms 256 KB
02_manual_04 WA 1 ms 256 KB
02_manual_05 WA 1 ms 256 KB
02_manual_06 WA 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 384 KB
20_random_01 AC 1 ms 384 KB
20_random_02 AC 1 ms 384 KB
20_random_03 AC 1 ms 384 KB
20_random_04 AC 1 ms 384 KB
20_random_05 AC 1 ms 384 KB
20_random_06 WA 1 ms 384 KB
20_random_07 AC 1 ms 384 KB
20_random_08 WA 1 ms 384 KB
20_random_09 AC 1 ms 384 KB
20_random_10 AC 1 ms 384 KB
20_random_11 AC 1 ms 384 KB
20_random_12 AC 1 ms 384 KB
20_random_13 WA 1 ms 256 KB
20_random_14 AC 1 ms 256 KB
20_random_15 WA 1 ms 256 KB
20_random_16 AC 1 ms 384 KB
20_random_17 AC 1 ms 384 KB
20_random_18 AC 1 ms 384 KB
20_random_19 AC 1 ms 384 KB
30_manual_13 WA 2 ms 768 KB
30_manual_14 AC 2 ms 768 KB
30_manual_15 WA 1 ms 384 KB
30_manual_16 WA 2 ms 768 KB
30_manual_17 AC 2 ms 768 KB
30_manual_18 AC 2 ms 768 KB
30_manual_19 AC 2 ms 768 KB