Submission #19250

# Submission time Handle Problem Language Result Execution time Memory
19250 2016-02-23T02:11:47 Z kaTkaHr 악수 (kriii4_D) C++14
5 / 100
3000 ms 25256 KB
#include <stdio.h>
#include<vector>
#include <algorithm>
#include <map>

using namespace std;

typedef long long ll;

const int MX = 105, MM = 1000000007;

ll rv(ll A){
	ll R = 1, B = MM-2;
	while(B){
		if( B&1 ) R = R * A % MM;
		A = A * A % MM; B /= 2;
	}
	return R;
}

struct frac{
	ll A, B;
	frac(ll a, ll b){
		A = (a%MM+MM) % MM;
		B = (b%MM+MM) % MM;
	}
	frac(){A = 0, B = 1;}
	frac operator+ (const frac &l)const{
		return frac((A * l.B + B * l.A) % MM, B * l.B % MM);
	}
	frac operator*(const frac &l)const{
		return frac(A*l.A % MM, B*l.B % MM);
	}
	frac operator/(const frac &l)const{
		return frac(A*l.B % MM, B*l.A % MM);
	}
	frac operator- (const frac &l)const{
		return frac((A*l.B - B*l.A%MM + MM) % MM, B*l.B % MM);
	}
	ll v(){ return A * rv(B) % MM; }
};

int ans = 0, N;
map<vector<int>, frac> L[900];

frac Solve(vector<int> &D, int T)
{
	if( L[T].find(D) != L[T].end() ) return L[T][D];
	vector<int> E;

	int tot = 0;
	for(int c : D) tot += c * (c-1) / 2;

	frac ans = frac(0, 1);
	frac chk = frac(0, 1);
	if( tot > T ) ans = Solve(D, T+1) * frac(tot - T, N*(N-1)/2 - T);
	if( tot > T ) chk = chk + frac(tot - T, N*(N-1)/2 - T);
	for(int i = 0; i < D.size(); i++){
		for(int j = i+1; j < D.size(); j++){
			E.clear();
			for(int k = 0; k < D.size(); k++){
				if( k == i ) E.push_back(D[i] + D[j]);
				else if( k == j );
				else E.push_back(D[k]);
			}
			sort(E.begin(), E.end());
			ans = ans + Solve(E, T+1) * frac(D[i] * D[j], N*(N-1)/2 - T);
			chk = chk + frac(D[i] * D[j], N*(N-1)/2 - T);
		}
	}
	ans = ans + frac(1, 1);
	return L[T][D] = ans;
}

int main()
{
	scanf("%d", &N);
	vector<int> D;
	D.push_back(N);
	for(int i = 0; i < N*N; i++) L[i][D] = frac(0, 1);
	D.clear();
	for(int i = 1; i <= N; i++) D.push_back(1);
	
	frac ans = Solve(D, 0);
	printf("%lld\n", ans.v());
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1628 KB Output is correct
2 Correct 0 ms 1628 KB Output is correct
3 Correct 0 ms 1628 KB Output is correct
4 Correct 0 ms 1628 KB Output is correct
5 Correct 0 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1628 KB Output is correct
2 Correct 0 ms 1628 KB Output is correct
3 Correct 0 ms 1628 KB Output is correct
4 Correct 0 ms 1628 KB Output is correct
5 Correct 0 ms 1628 KB Output is correct
6 Correct 0 ms 1628 KB Output is correct
7 Correct 2 ms 1628 KB Output is correct
8 Correct 4 ms 1760 KB Output is correct
9 Correct 7 ms 1760 KB Output is correct
10 Correct 12 ms 1892 KB Output is correct
11 Correct 20 ms 2024 KB Output is correct
12 Correct 33 ms 2288 KB Output is correct
13 Correct 49 ms 2684 KB Output is correct
14 Correct 81 ms 3080 KB Output is correct
15 Correct 129 ms 3740 KB Output is correct
16 Correct 209 ms 4532 KB Output is correct
17 Correct 314 ms 5588 KB Output is correct
18 Correct 484 ms 7040 KB Output is correct
19 Correct 717 ms 9020 KB Output is correct
20 Correct 1073 ms 11660 KB Output is correct
21 Correct 1569 ms 14960 KB Output is correct
22 Correct 2265 ms 19448 KB Output is correct
23 Execution timed out 3000 ms 25256 KB Program timed out
24 Halted 0 ms 0 KB -