답안 #19487

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
19487 2016-02-24T14:06:52 Z kaTkaHr 악수 (kriii4_D) C++14
5 / 100
3000 ms 34544 KB
#include <stdio.h>
#include<vector>
#include <algorithm>
#include <map>

using namespace std;

typedef long long ll;

const int MX = 45, MM = 1000000007;

template<typename T>
T pw(T A, ll B){
  T R = 1;
  while(B){
    if( B&1 ) R = R * A;
    A = A * A; B /= 2;
  }
  return R;
}

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):A(A), B(1){}
  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; }
};// */
//*
struct frac{
  ll A;
		frac(ll A):A((A%MM+MM)%MM){}
  frac(ll a, ll b){
			a = (a%MM+MM)%MM;
			b = (b%MM+MM)%MM;
			A = rv(b) * a % MM;
  }
  frac(){A = 0;}
  frac operator+ (const frac &l)const{
			return l.A + A >= MM? l.A + A - MM: l.A + A;
  }
  frac operator*(const frac &l)const{
			return l.A * A % MM;
  }
  frac operator/(const frac &l)const{
			return A * rv(l.A) % MM;
  }
  frac operator- (const frac &l)const{
			return A >= l.A? A-l.A: A-l.A + MM;
  }
  ll v(){ return A; }
};// */

frac D[MX][MX*MX], E[MX][MX*MX], C[MX*MX][MX*MX];

int main()
{
	int N, T;
	scanf("%d", &N); T = N*(N-1) / 2;

	C[0][0] = 1;
	for(int i = 1; i <= T || i <= N; i++){
		C[i][0] = 1;
		for(int j = 1; j <= i; j++){
			C[i][j] = C[i-1][j-1] + C[i-1][j];
		}
	}

	D[1][0] = E[1][0] = 1;
	for(int i = 2; i <= N; i++){
		for(int x = i-1; x <= i*(i-1)/2; x++){
			for(int k = 1; k <= i-1; k++){
				for(int l = 0; l <= x-1; l++){
					E[i][x] = E[i][x] + D[k][l] * D[i-k][x-l-1] * frac(k*(i-k), 1) * C[i][k] * C[x-1][l];
				}
			}
			E[i][x] = E[i][x] / 2;
			D[i][x] = D[i][x-1] * frac(i*(i-1)/2 - x + 1, 1) + E[i][x];
		}
	}
	frac ans = 0, mul = 1;
	frac tot = 0;
	for(int i = 0; i <= T; i++){
		tot = tot + E[N][i] * mul;
		ans = ans + E[N][i] * i * mul;
		mul = mul * frac(1, T-i);
	}
	printf("%lld\n", ans.v());
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 34544 KB Output is correct
2 Correct 0 ms 34544 KB Output is correct
3 Correct 4 ms 34544 KB Output is correct
4 Correct 0 ms 34544 KB Output is correct
5 Correct 0 ms 34544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 34544 KB Output is correct
2 Correct 4 ms 34544 KB Output is correct
3 Correct 4 ms 34544 KB Output is correct
4 Correct 0 ms 34544 KB Output is correct
5 Correct 3 ms 34544 KB Output is correct
6 Correct 10 ms 34544 KB Output is correct
7 Correct 4 ms 34544 KB Output is correct
8 Correct 11 ms 34544 KB Output is correct
9 Correct 9 ms 34544 KB Output is correct
10 Correct 16 ms 34544 KB Output is correct
11 Correct 24 ms 34544 KB Output is correct
12 Correct 43 ms 34544 KB Output is correct
13 Correct 53 ms 34544 KB Output is correct
14 Correct 76 ms 34544 KB Output is correct
15 Correct 93 ms 34544 KB Output is correct
16 Correct 124 ms 34544 KB Output is correct
17 Correct 165 ms 34544 KB Output is correct
18 Correct 219 ms 34544 KB Output is correct
19 Correct 282 ms 34544 KB Output is correct
20 Correct 356 ms 34544 KB Output is correct
21 Correct 458 ms 34544 KB Output is correct
22 Correct 569 ms 34544 KB Output is correct
23 Correct 704 ms 34544 KB Output is correct
24 Correct 870 ms 34544 KB Output is correct
25 Correct 1072 ms 34544 KB Output is correct
26 Correct 1300 ms 34544 KB Output is correct
27 Correct 1575 ms 34544 KB Output is correct
28 Correct 1902 ms 34544 KB Output is correct
29 Correct 2267 ms 34544 KB Output is correct
30 Correct 2701 ms 34544 KB Output is correct
31 Execution timed out 3000 ms 34544 KB Program timed out
32 Halted 0 ms 0 KB -