답안 #679174

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
679174 2023-01-07T16:12:05 Z rainboy Asceticism (JOI18_asceticism) C
100 / 100
9 ms 1492 KB
#include <stdio.h>

#define N	100000
#define MD	1000000007

int vv[N + 2], ff[N + 2], gg[N + 2];

void init() {
	int i;

	ff[0] = gg[0] = 1;
	for (i = 1; i <= N + 1; i++) {
		vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD;
		ff[i] = (long long) ff[i - 1] * i % MD;
		gg[i] = (long long) gg[i - 1] * vv[i] % MD;
	}
}

int choose(int n, int k) {
	return (long long) ff[n] * gg[k] % MD * gg[n - k] % MD;
}

long long power(long long a, int k) {
	long long p = 1;

	while (k) {
		if (k & 1)
			p = p * a % MD;
		a = a * a % MD;
		k >>= 1;
	}
	return p;
}

int main() {
	int n, k, m, ans;

	init();
	scanf("%d%d", &n, &k);
	ans = 0;
	for (m = 0; m <= k; m++)
		ans = (ans + power(m, n) * choose(n + 1, k - m) * ((k - m) % 2 == 0 ? 1 : -1)) % MD;
	if (ans < 0)
		ans += MD;
	printf("%d\n", ans);
	return 0;
}

Compilation message

asceticism.c: In function 'main':
asceticism.c:39:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  scanf("%d%d", &n, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1492 KB Output is correct
2 Correct 2 ms 1460 KB Output is correct
3 Correct 2 ms 1364 KB Output is correct
4 Correct 2 ms 1364 KB Output is correct
5 Correct 2 ms 1384 KB Output is correct
6 Correct 2 ms 1456 KB Output is correct
7 Correct 2 ms 1460 KB Output is correct
8 Correct 2 ms 1456 KB Output is correct
9 Correct 2 ms 1364 KB Output is correct
10 Correct 2 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1492 KB Output is correct
2 Correct 2 ms 1460 KB Output is correct
3 Correct 2 ms 1364 KB Output is correct
4 Correct 2 ms 1364 KB Output is correct
5 Correct 2 ms 1384 KB Output is correct
6 Correct 2 ms 1456 KB Output is correct
7 Correct 2 ms 1460 KB Output is correct
8 Correct 2 ms 1456 KB Output is correct
9 Correct 2 ms 1364 KB Output is correct
10 Correct 2 ms 1364 KB Output is correct
11 Correct 2 ms 1364 KB Output is correct
12 Correct 2 ms 1460 KB Output is correct
13 Correct 1 ms 1456 KB Output is correct
14 Correct 1 ms 1364 KB Output is correct
15 Correct 2 ms 1364 KB Output is correct
16 Correct 2 ms 1364 KB Output is correct
17 Correct 2 ms 1364 KB Output is correct
18 Correct 2 ms 1364 KB Output is correct
19 Correct 1 ms 1460 KB Output is correct
20 Correct 2 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1492 KB Output is correct
2 Correct 2 ms 1460 KB Output is correct
3 Correct 2 ms 1364 KB Output is correct
4 Correct 2 ms 1364 KB Output is correct
5 Correct 2 ms 1384 KB Output is correct
6 Correct 2 ms 1456 KB Output is correct
7 Correct 2 ms 1460 KB Output is correct
8 Correct 2 ms 1456 KB Output is correct
9 Correct 2 ms 1364 KB Output is correct
10 Correct 2 ms 1364 KB Output is correct
11 Correct 2 ms 1364 KB Output is correct
12 Correct 2 ms 1460 KB Output is correct
13 Correct 1 ms 1456 KB Output is correct
14 Correct 1 ms 1364 KB Output is correct
15 Correct 2 ms 1364 KB Output is correct
16 Correct 2 ms 1364 KB Output is correct
17 Correct 2 ms 1364 KB Output is correct
18 Correct 2 ms 1364 KB Output is correct
19 Correct 1 ms 1460 KB Output is correct
20 Correct 2 ms 1364 KB Output is correct
21 Correct 3 ms 1460 KB Output is correct
22 Correct 2 ms 1460 KB Output is correct
23 Correct 2 ms 1364 KB Output is correct
24 Correct 2 ms 1368 KB Output is correct
25 Correct 2 ms 1364 KB Output is correct
26 Correct 2 ms 1460 KB Output is correct
27 Correct 2 ms 1364 KB Output is correct
28 Correct 2 ms 1364 KB Output is correct
29 Correct 2 ms 1460 KB Output is correct
30 Correct 2 ms 1460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1492 KB Output is correct
2 Correct 2 ms 1460 KB Output is correct
3 Correct 2 ms 1364 KB Output is correct
4 Correct 2 ms 1364 KB Output is correct
5 Correct 2 ms 1384 KB Output is correct
6 Correct 2 ms 1456 KB Output is correct
7 Correct 2 ms 1460 KB Output is correct
8 Correct 2 ms 1456 KB Output is correct
9 Correct 2 ms 1364 KB Output is correct
10 Correct 2 ms 1364 KB Output is correct
11 Correct 2 ms 1364 KB Output is correct
12 Correct 2 ms 1460 KB Output is correct
13 Correct 1 ms 1456 KB Output is correct
14 Correct 1 ms 1364 KB Output is correct
15 Correct 2 ms 1364 KB Output is correct
16 Correct 2 ms 1364 KB Output is correct
17 Correct 2 ms 1364 KB Output is correct
18 Correct 2 ms 1364 KB Output is correct
19 Correct 1 ms 1460 KB Output is correct
20 Correct 2 ms 1364 KB Output is correct
21 Correct 3 ms 1460 KB Output is correct
22 Correct 2 ms 1460 KB Output is correct
23 Correct 2 ms 1364 KB Output is correct
24 Correct 2 ms 1368 KB Output is correct
25 Correct 2 ms 1364 KB Output is correct
26 Correct 2 ms 1460 KB Output is correct
27 Correct 2 ms 1364 KB Output is correct
28 Correct 2 ms 1364 KB Output is correct
29 Correct 2 ms 1460 KB Output is correct
30 Correct 2 ms 1460 KB Output is correct
31 Correct 2 ms 1364 KB Output is correct
32 Correct 2 ms 1364 KB Output is correct
33 Correct 2 ms 1364 KB Output is correct
34 Correct 3 ms 1364 KB Output is correct
35 Correct 8 ms 1460 KB Output is correct
36 Correct 9 ms 1460 KB Output is correct
37 Correct 9 ms 1364 KB Output is correct
38 Correct 3 ms 1364 KB Output is correct
39 Correct 4 ms 1460 KB Output is correct
40 Correct 5 ms 1456 KB Output is correct