답안 #19491

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
19491 2016-02-24T14:10:07 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-1][k-1] * C[x-1][l];
				}
			}
			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 8 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 4 ms 34544 KB Output is correct
5 Correct 8 ms 34544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 4 ms 34544 KB Output is correct
5 Correct 9 ms 34544 KB Output is correct
6 Correct 7 ms 34544 KB Output is correct
7 Correct 8 ms 34544 KB Output is correct
8 Correct 7 ms 34544 KB Output is correct
9 Correct 7 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 39 ms 34544 KB Output is correct
13 Correct 49 ms 34544 KB Output is correct
14 Correct 68 ms 34544 KB Output is correct
15 Correct 96 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 220 ms 34544 KB Output is correct
19 Correct 285 ms 34544 KB Output is correct
20 Correct 359 ms 34544 KB Output is correct
21 Correct 449 ms 34544 KB Output is correct
22 Correct 569 ms 34544 KB Output is correct
23 Correct 708 ms 34544 KB Output is correct
24 Correct 872 ms 34544 KB Output is correct
25 Correct 1065 ms 34544 KB Output is correct
26 Correct 1298 ms 34544 KB Output is correct
27 Correct 1585 ms 34544 KB Output is correct
28 Correct 1895 ms 34544 KB Output is correct
29 Correct 2262 ms 34544 KB Output is correct
30 Correct 2704 ms 34544 KB Output is correct
31 Execution timed out 3000 ms 34544 KB Program timed out
32 Halted 0 ms 0 KB -