답안 #19256

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
19256 2016-02-23T05:03:54 Z kaTkaHr 순열 (kriii4_T) C++14
100 / 100
72 ms 1084 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):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; }
};

int main()
{
	int N, KK;
	scanf("%d%d", &N, &KK); 
	frac tot = 0, mul = 1;
	for(int i = 1; i <= N+1; i++){
		mul = mul * i;
	}
	for(int K = KK+1; K <= N; K++){
/*		for(int i = N; i >= 1; i--){
			mul = mul / i;
			ans = ans + mul * (N-i+1);
			mul = mul * (i-K);
		}
		ans = ans * K * (N-K+1);*/
		tot = tot + mul * (N-K+1) / (K+1);
	}
	printf("%lld\n", tot.v());
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1084 KB Output is correct
2 Correct 0 ms 1084 KB Output is correct
3 Correct 0 ms 1084 KB Output is correct
4 Correct 0 ms 1084 KB Output is correct
5 Correct 0 ms 1084 KB Output is correct
6 Correct 0 ms 1084 KB Output is correct
7 Correct 0 ms 1084 KB Output is correct
8 Correct 0 ms 1084 KB Output is correct
9 Correct 0 ms 1084 KB Output is correct
10 Correct 0 ms 1084 KB Output is correct
11 Correct 0 ms 1084 KB Output is correct
12 Correct 0 ms 1084 KB Output is correct
13 Correct 0 ms 1084 KB Output is correct
14 Correct 0 ms 1084 KB Output is correct
15 Correct 0 ms 1084 KB Output is correct
16 Correct 0 ms 1084 KB Output is correct
17 Correct 0 ms 1084 KB Output is correct
18 Correct 0 ms 1084 KB Output is correct
19 Correct 0 ms 1084 KB Output is correct
20 Correct 0 ms 1084 KB Output is correct
21 Correct 0 ms 1084 KB Output is correct
22 Correct 0 ms 1084 KB Output is correct
23 Correct 0 ms 1084 KB Output is correct
24 Correct 0 ms 1084 KB Output is correct
25 Correct 0 ms 1084 KB Output is correct
26 Correct 0 ms 1084 KB Output is correct
27 Correct 0 ms 1084 KB Output is correct
28 Correct 0 ms 1084 KB Output is correct
29 Correct 0 ms 1084 KB Output is correct
30 Correct 0 ms 1084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 1084 KB Output is correct
2 Correct 31 ms 1084 KB Output is correct
3 Correct 22 ms 1084 KB Output is correct
4 Correct 8 ms 1084 KB Output is correct
5 Correct 10 ms 1084 KB Output is correct
6 Correct 20 ms 1084 KB Output is correct
7 Correct 55 ms 1084 KB Output is correct
8 Correct 33 ms 1084 KB Output is correct
9 Correct 12 ms 1084 KB Output is correct
10 Correct 3 ms 1084 KB Output is correct
11 Correct 22 ms 1084 KB Output is correct
12 Correct 13 ms 1084 KB Output is correct
13 Correct 22 ms 1084 KB Output is correct
14 Correct 51 ms 1084 KB Output is correct
15 Correct 30 ms 1084 KB Output is correct
16 Correct 41 ms 1084 KB Output is correct
17 Correct 26 ms 1084 KB Output is correct
18 Correct 20 ms 1084 KB Output is correct
19 Correct 9 ms 1084 KB Output is correct
20 Correct 31 ms 1084 KB Output is correct
21 Correct 16 ms 1084 KB Output is correct
22 Correct 43 ms 1084 KB Output is correct
23 Correct 23 ms 1084 KB Output is correct
24 Correct 9 ms 1084 KB Output is correct
25 Correct 18 ms 1084 KB Output is correct
26 Correct 30 ms 1084 KB Output is correct
27 Correct 3 ms 1084 KB Output is correct
28 Correct 19 ms 1084 KB Output is correct
29 Correct 72 ms 1084 KB Output is correct
30 Correct 72 ms 1084 KB Output is correct