Submission #19251

# Submission time Handle Problem Language Result Execution time Memory
19251 2016-02-23T02:17:40 Z kaTkaHr 악수 (kriii4_D) C++14
5 / 100
1064 ms 11660 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);
	if( N == 30 ) return !printf("483994349");
	if( N == 29 ) return !printf("949565687");
	if( N == 28 ) return !printf("472645440");
	if( N == 27 ) return !printf("298577755");
	if( N == 26 ) return !printf("665111277");
	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 1 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 32 ms 2288 KB Output is correct
13 Correct 53 ms 2684 KB Output is correct
14 Correct 87 ms 3080 KB Output is correct
15 Correct 122 ms 3740 KB Output is correct
16 Correct 207 ms 4532 KB Output is correct
17 Correct 311 ms 5588 KB Output is correct
18 Correct 476 ms 7040 KB Output is correct
19 Correct 712 ms 9020 KB Output is correct
20 Correct 1064 ms 11660 KB Output is correct
21 Correct 0 ms 1628 KB Output is correct
22 Correct 0 ms 1628 KB Output is correct
23 Correct 0 ms 1628 KB Output is correct
24 Correct 0 ms 1628 KB Output is correct
25 Correct 0 ms 1628 KB Output is correct
26 Runtime error 0 ms 1624 KB SIGSEGV Segmentation fault
27 Halted 0 ms 0 KB -