Submission #1834209


Source Code Expand

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 33
int n, a[N][N];
double p, dp[N][N], dp2[N][N], dp3[N][N];
int main(){
	int x, y;
	scanf("%d %d/%d", &n, &x, &y);
	p = (double)x/y;
	rep(i, n) rep(j, n) scanf("%d", a[i]+j);
	vector<P> v(n);
	rep(i, n){
		int cnt = 0;
		rep(j, n) cnt += a[i][j];
		v[i] = P(-cnt, i);
	}
	sort(all(v));
	rep(i, n){
		mset(dp3, 0);
		dp3[0][0] = 1;
		rep(j, n-1){
			if(i==j) swap(a[i][j], a[i][n-1]);
			for(int k = n; k >= 0; k--){
				dp3[j+1][k+a[i][j]] += dp3[j][k]*p;
				dp3[j+1][k+!a[i][j]] += dp3[j][k]*(1-p);
			}
		}
		memcpy(dp[i], dp3[n-1], sizeof(dp[0]));
	}
	//rep(i, n) rep(j, n) cerr<<dp[i][j]<<(j==n-1?'\n':' ');
	for(int j = n; j >= 0; j--) dp2[v[0].snd][j] += dp2[v[0].snd][j+1]+dp[v[0].snd][j];
	rep(i, n-1){
		int i1 = v[i].snd;
		int i2 = v[i+1].snd;
		for(int j = n; j >=0; j--){
			int j1 = j+(i1>i2);
			dp2[i2][j] = dp[i2][j]*dp2[i1][j1]+dp2[i2][j+1];
		}
	}
	//rep(i, n) rep(j, n) cerr<<dp2[i][j]<<(j==n-1?'\n':' ');
	double res = 0;
	res = dp2[v[n-1].snd][0];
	cout.precision(11);
	cout<<res<<endl;
	return 0;
}

Submission Info

Submission Time
Task C - 天下一プログラマーコンテスト1999
User Lepton
Language C++14 (GCC 5.4.1)
Score 600
Code Size 2238 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:46:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d/%d", &n, &x, &y);
                               ^
./Main.cpp:48:41: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  rep(i, n) rep(j, n) scanf("%d", a[i]+j);
                                         ^

Judge Result

Set Name All
Score / Max Score 600 / 600
Status
AC × 43
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 AC 1 ms 256 KB
02_manual_09 AC 1 ms 256 KB
02_manual_10 AC 1 ms 256 KB
02_manual_11 AC 1 ms 256 KB
02_manual_12 AC 1 ms 256 KB
20_random_00 AC 1 ms 256 KB
20_random_01 AC 1 ms 256 KB
20_random_02 AC 1 ms 256 KB
20_random_03 AC 1 ms 256 KB
20_random_04 AC 1 ms 256 KB
20_random_05 AC 1 ms 256 KB
20_random_06 AC 1 ms 256 KB
20_random_07 AC 1 ms 256 KB
20_random_08 AC 1 ms 256 KB
20_random_09 AC 1 ms 256 KB
20_random_10 AC 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 AC 1 ms 256 KB
20_random_18 AC 1 ms 256 KB
20_random_19 AC 1 ms 256 KB
30_manual_13 AC 1 ms 256 KB
30_manual_14 AC 1 ms 256 KB
30_manual_15 AC 1 ms 256 KB
30_manual_16 AC 1 ms 256 KB
30_manual_17 AC 1 ms 256 KB
30_manual_18 AC 1 ms 256 KB
30_manual_19 AC 1 ms 256 KB