Submission #723152

# Submission time Handle Problem Language Result Execution time Memory
723152 2023-04-13T09:24:39 Z Sohsoh84 Asceticism (JOI18_asceticism) C++17
100 / 100
24 ms 2004 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

const ll MAXN = 1e5 + 10;
const ll MOD = 1e9 + 7;

inline ll poww(ll a, ll b) {
	ll ans = 1;
	while (b) {
		if (b & 1) ans = ans * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}

	return ans;
}

ll fact[MAXN], inv[MAXN];

inline ll C(ll k, ll n) {
	if (k < 0 || k > n) return 0;
	return fact[n] * inv[k] % MOD * inv[n - k] % MOD;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	fact[0] = inv[0] = 1;
	for (int i = 1; i < MAXN; i++) {
		fact[i] = fact[i - 1] * i % MOD;
		inv[i] = poww(fact[i], MOD - 2);
	}

	ll ans = 0;
	ll n, k;
	cin >> n >> k;
	for (int i = 0; i <= k; i++) {
		ans = (ans + MOD + (i & 1 ? -1 : 1) * C(i, n + 1) * poww(k - i, n) % MOD) % MOD;
	}

	cout << ans << endl;
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 16 ms 1876 KB Output is correct
2 Correct 14 ms 1828 KB Output is correct
3 Correct 16 ms 1768 KB Output is correct
4 Correct 15 ms 1784 KB Output is correct
5 Correct 15 ms 1876 KB Output is correct
6 Correct 15 ms 1848 KB Output is correct
7 Correct 15 ms 1800 KB Output is correct
8 Correct 15 ms 1864 KB Output is correct
9 Correct 16 ms 1876 KB Output is correct
10 Correct 15 ms 1840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1876 KB Output is correct
2 Correct 14 ms 1828 KB Output is correct
3 Correct 16 ms 1768 KB Output is correct
4 Correct 15 ms 1784 KB Output is correct
5 Correct 15 ms 1876 KB Output is correct
6 Correct 15 ms 1848 KB Output is correct
7 Correct 15 ms 1800 KB Output is correct
8 Correct 15 ms 1864 KB Output is correct
9 Correct 16 ms 1876 KB Output is correct
10 Correct 15 ms 1840 KB Output is correct
11 Correct 16 ms 1832 KB Output is correct
12 Correct 15 ms 1884 KB Output is correct
13 Correct 15 ms 1796 KB Output is correct
14 Correct 16 ms 1884 KB Output is correct
15 Correct 16 ms 1776 KB Output is correct
16 Correct 15 ms 1852 KB Output is correct
17 Correct 15 ms 1876 KB Output is correct
18 Correct 15 ms 1876 KB Output is correct
19 Correct 16 ms 1792 KB Output is correct
20 Correct 15 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1876 KB Output is correct
2 Correct 14 ms 1828 KB Output is correct
3 Correct 16 ms 1768 KB Output is correct
4 Correct 15 ms 1784 KB Output is correct
5 Correct 15 ms 1876 KB Output is correct
6 Correct 15 ms 1848 KB Output is correct
7 Correct 15 ms 1800 KB Output is correct
8 Correct 15 ms 1864 KB Output is correct
9 Correct 16 ms 1876 KB Output is correct
10 Correct 15 ms 1840 KB Output is correct
11 Correct 16 ms 1832 KB Output is correct
12 Correct 15 ms 1884 KB Output is correct
13 Correct 15 ms 1796 KB Output is correct
14 Correct 16 ms 1884 KB Output is correct
15 Correct 16 ms 1776 KB Output is correct
16 Correct 15 ms 1852 KB Output is correct
17 Correct 15 ms 1876 KB Output is correct
18 Correct 15 ms 1876 KB Output is correct
19 Correct 16 ms 1792 KB Output is correct
20 Correct 15 ms 1884 KB Output is correct
21 Correct 14 ms 1780 KB Output is correct
22 Correct 15 ms 1876 KB Output is correct
23 Correct 15 ms 1788 KB Output is correct
24 Correct 16 ms 2004 KB Output is correct
25 Correct 15 ms 1876 KB Output is correct
26 Correct 14 ms 1876 KB Output is correct
27 Correct 14 ms 1812 KB Output is correct
28 Correct 14 ms 1960 KB Output is correct
29 Correct 14 ms 1876 KB Output is correct
30 Correct 14 ms 1872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1876 KB Output is correct
2 Correct 14 ms 1828 KB Output is correct
3 Correct 16 ms 1768 KB Output is correct
4 Correct 15 ms 1784 KB Output is correct
5 Correct 15 ms 1876 KB Output is correct
6 Correct 15 ms 1848 KB Output is correct
7 Correct 15 ms 1800 KB Output is correct
8 Correct 15 ms 1864 KB Output is correct
9 Correct 16 ms 1876 KB Output is correct
10 Correct 15 ms 1840 KB Output is correct
11 Correct 16 ms 1832 KB Output is correct
12 Correct 15 ms 1884 KB Output is correct
13 Correct 15 ms 1796 KB Output is correct
14 Correct 16 ms 1884 KB Output is correct
15 Correct 16 ms 1776 KB Output is correct
16 Correct 15 ms 1852 KB Output is correct
17 Correct 15 ms 1876 KB Output is correct
18 Correct 15 ms 1876 KB Output is correct
19 Correct 16 ms 1792 KB Output is correct
20 Correct 15 ms 1884 KB Output is correct
21 Correct 14 ms 1780 KB Output is correct
22 Correct 15 ms 1876 KB Output is correct
23 Correct 15 ms 1788 KB Output is correct
24 Correct 16 ms 2004 KB Output is correct
25 Correct 15 ms 1876 KB Output is correct
26 Correct 14 ms 1876 KB Output is correct
27 Correct 14 ms 1812 KB Output is correct
28 Correct 14 ms 1960 KB Output is correct
29 Correct 14 ms 1876 KB Output is correct
30 Correct 14 ms 1872 KB Output is correct
31 Correct 14 ms 1876 KB Output is correct
32 Correct 14 ms 1892 KB Output is correct
33 Correct 16 ms 1876 KB Output is correct
34 Correct 16 ms 1864 KB Output is correct
35 Correct 21 ms 1888 KB Output is correct
36 Correct 22 ms 1764 KB Output is correct
37 Correct 24 ms 1876 KB Output is correct
38 Correct 16 ms 1804 KB Output is correct
39 Correct 19 ms 1768 KB Output is correct
40 Correct 19 ms 1868 KB Output is correct