Submission #120138

# Submission time Handle Problem Language Result Execution time Memory
120138 2019-06-23T14:18:40 Z arman_ferdous Asceticism (JOI18_asceticism) C++17
100 / 100
12 ms 1920 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const int N = 1e5+100;
const int MOD = 1e9+7;

ll powmod(ll a, ll b, ll r = 1) {
	while(b) {
		if(b & 1) r = r * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	} return r;
}

ll fac[N], inv[N];
void prep() {
	fac[0] = 1;
	for(ll i = 1; i < N; i++)
		fac[i] = i * fac[i - 1] % MOD;
	inv[N - 1] = powmod(fac[N - 1], MOD - 2);
	for(ll i = N - 2; i >= 0; i--) 
		inv[i] = inv[i + 1] * (i + 1) % MOD;
}

ll C(int n, int r) {
	return fac[n] * (inv[r] * inv[n - r] % MOD) % MOD;
}

int main() {
	prep();
	int n, k; scanf("%d %d", &n, &k);
	ll eulerian = 0;
	for(int i = 0, mark = 1; i < k; i++, mark = -mark) {
		ll tmp = C(n + 1, i) * powmod(k - i, n) % MOD;
		tmp *= mark;
		while(tmp < 0) tmp += MOD;
		eulerian += tmp;
		if(eulerian >= MOD) eulerian -= MOD;
	}
	printf("%lld", eulerian);
	return 0;
}

Compilation message

asceticism.cpp: In function 'int main()':
asceticism.cpp:32:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n, k; scanf("%d %d", &n, &k);
            ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1920 KB Output is correct
2 Correct 4 ms 1920 KB Output is correct
3 Correct 4 ms 1920 KB Output is correct
4 Correct 4 ms 1920 KB Output is correct
5 Correct 4 ms 1920 KB Output is correct
6 Correct 4 ms 1920 KB Output is correct
7 Correct 4 ms 1920 KB Output is correct
8 Correct 4 ms 1920 KB Output is correct
9 Correct 4 ms 1920 KB Output is correct
10 Correct 4 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1920 KB Output is correct
2 Correct 4 ms 1920 KB Output is correct
3 Correct 4 ms 1920 KB Output is correct
4 Correct 4 ms 1920 KB Output is correct
5 Correct 4 ms 1920 KB Output is correct
6 Correct 4 ms 1920 KB Output is correct
7 Correct 4 ms 1920 KB Output is correct
8 Correct 4 ms 1920 KB Output is correct
9 Correct 4 ms 1920 KB Output is correct
10 Correct 4 ms 1920 KB Output is correct
11 Correct 4 ms 1920 KB Output is correct
12 Correct 4 ms 1920 KB Output is correct
13 Correct 4 ms 1920 KB Output is correct
14 Correct 4 ms 1920 KB Output is correct
15 Correct 5 ms 1920 KB Output is correct
16 Correct 4 ms 1920 KB Output is correct
17 Correct 5 ms 1920 KB Output is correct
18 Correct 4 ms 1920 KB Output is correct
19 Correct 4 ms 1920 KB Output is correct
20 Correct 4 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1920 KB Output is correct
2 Correct 4 ms 1920 KB Output is correct
3 Correct 4 ms 1920 KB Output is correct
4 Correct 4 ms 1920 KB Output is correct
5 Correct 4 ms 1920 KB Output is correct
6 Correct 4 ms 1920 KB Output is correct
7 Correct 4 ms 1920 KB Output is correct
8 Correct 4 ms 1920 KB Output is correct
9 Correct 4 ms 1920 KB Output is correct
10 Correct 4 ms 1920 KB Output is correct
11 Correct 4 ms 1920 KB Output is correct
12 Correct 4 ms 1920 KB Output is correct
13 Correct 4 ms 1920 KB Output is correct
14 Correct 4 ms 1920 KB Output is correct
15 Correct 5 ms 1920 KB Output is correct
16 Correct 4 ms 1920 KB Output is correct
17 Correct 5 ms 1920 KB Output is correct
18 Correct 4 ms 1920 KB Output is correct
19 Correct 4 ms 1920 KB Output is correct
20 Correct 4 ms 1920 KB Output is correct
21 Correct 4 ms 1920 KB Output is correct
22 Correct 4 ms 1920 KB Output is correct
23 Correct 4 ms 1920 KB Output is correct
24 Correct 4 ms 1920 KB Output is correct
25 Correct 4 ms 1920 KB Output is correct
26 Correct 4 ms 1920 KB Output is correct
27 Correct 4 ms 1920 KB Output is correct
28 Correct 4 ms 1920 KB Output is correct
29 Correct 4 ms 1920 KB Output is correct
30 Correct 5 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1920 KB Output is correct
2 Correct 4 ms 1920 KB Output is correct
3 Correct 4 ms 1920 KB Output is correct
4 Correct 4 ms 1920 KB Output is correct
5 Correct 4 ms 1920 KB Output is correct
6 Correct 4 ms 1920 KB Output is correct
7 Correct 4 ms 1920 KB Output is correct
8 Correct 4 ms 1920 KB Output is correct
9 Correct 4 ms 1920 KB Output is correct
10 Correct 4 ms 1920 KB Output is correct
11 Correct 4 ms 1920 KB Output is correct
12 Correct 4 ms 1920 KB Output is correct
13 Correct 4 ms 1920 KB Output is correct
14 Correct 4 ms 1920 KB Output is correct
15 Correct 5 ms 1920 KB Output is correct
16 Correct 4 ms 1920 KB Output is correct
17 Correct 5 ms 1920 KB Output is correct
18 Correct 4 ms 1920 KB Output is correct
19 Correct 4 ms 1920 KB Output is correct
20 Correct 4 ms 1920 KB Output is correct
21 Correct 4 ms 1920 KB Output is correct
22 Correct 4 ms 1920 KB Output is correct
23 Correct 4 ms 1920 KB Output is correct
24 Correct 4 ms 1920 KB Output is correct
25 Correct 4 ms 1920 KB Output is correct
26 Correct 4 ms 1920 KB Output is correct
27 Correct 4 ms 1920 KB Output is correct
28 Correct 4 ms 1920 KB Output is correct
29 Correct 4 ms 1920 KB Output is correct
30 Correct 5 ms 1920 KB Output is correct
31 Correct 4 ms 1920 KB Output is correct
32 Correct 4 ms 1920 KB Output is correct
33 Correct 5 ms 1840 KB Output is correct
34 Correct 6 ms 1920 KB Output is correct
35 Correct 11 ms 1920 KB Output is correct
36 Correct 12 ms 1920 KB Output is correct
37 Correct 12 ms 1920 KB Output is correct
38 Correct 6 ms 1920 KB Output is correct
39 Correct 7 ms 1920 KB Output is correct
40 Correct 8 ms 1920 KB Output is correct