Submission #764162

# Submission time Handle Problem Language Result Execution time Memory
764162 2023-06-23T08:06:28 Z minhcool Asceticism (JOI18_asceticism) C++17
100 / 100
30 ms 3564 KB
#define local
#ifndef local
#include ""
#endif
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 3e5 + 5;

const int oo = 1e18 + 7, mod = 1e9 + 7;

mt19937 rng(1);

int rnd(int l, int r){
	int temp = rng() % (r - l + 1);
	return abs(temp) + l;
}

#ifdef local

int n, k;

int fac[N], invfac[N];

int c(int n, int k){
	int temp = (fac[n] * invfac[k]) % mod;
	//cout << temp << "\n";
	temp = (temp * invfac[n - k]) % mod;
	//cout << temp << "\n";
	return temp;
}

int binpw(int base, int pw){
	int ans = 1;
	while(pw){
		if(pw & 1) ans = (ans * base) % mod;
		base = (base * base) % mod;
		pw >>= 1;
	}
	return ans;
}

void process(){
	cin >> n >> k;
	//dp[1][1] = 1;
	fac[0] = invfac[0] = 1;
	for(int i = 1; i <= 200000; i++){
		fac[i] = (fac[i - 1] * i) % mod;
		invfac[i] = (invfac[i - 1] * binpw(i, mod - 2)) % mod;
		//cout << fac[i] << " " << invfac[i] << "\n";
	}
	int answer = 0;
	k--;
	for(int i = 0; i <= k + 1; i++){
		int sig = (i & 1 ? -1 : 1);
		sig = sig * c(n + 1, i) * binpw(k - i + 1, n);
		//cout << c(n + 1, i) << " " << binpw(k - i + 1, n) << "\n";
		//cout << sig << "\n";
		sig = ((sig % mod) + mod) % mod;
		answer = (answer + sig) % mod;
	}
	cout << answer << "\n";
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	process();
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3348 KB Output is correct
2 Correct 24 ms 3372 KB Output is correct
3 Correct 24 ms 3384 KB Output is correct
4 Correct 24 ms 3412 KB Output is correct
5 Correct 24 ms 3452 KB Output is correct
6 Correct 25 ms 3372 KB Output is correct
7 Correct 24 ms 3412 KB Output is correct
8 Correct 24 ms 3392 KB Output is correct
9 Correct 24 ms 3448 KB Output is correct
10 Correct 24 ms 3348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3348 KB Output is correct
2 Correct 24 ms 3372 KB Output is correct
3 Correct 24 ms 3384 KB Output is correct
4 Correct 24 ms 3412 KB Output is correct
5 Correct 24 ms 3452 KB Output is correct
6 Correct 25 ms 3372 KB Output is correct
7 Correct 24 ms 3412 KB Output is correct
8 Correct 24 ms 3392 KB Output is correct
9 Correct 24 ms 3448 KB Output is correct
10 Correct 24 ms 3348 KB Output is correct
11 Correct 24 ms 3388 KB Output is correct
12 Correct 24 ms 3412 KB Output is correct
13 Correct 24 ms 3456 KB Output is correct
14 Correct 24 ms 3412 KB Output is correct
15 Correct 25 ms 3392 KB Output is correct
16 Correct 25 ms 3564 KB Output is correct
17 Correct 24 ms 3400 KB Output is correct
18 Correct 24 ms 3376 KB Output is correct
19 Correct 24 ms 3380 KB Output is correct
20 Correct 24 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3348 KB Output is correct
2 Correct 24 ms 3372 KB Output is correct
3 Correct 24 ms 3384 KB Output is correct
4 Correct 24 ms 3412 KB Output is correct
5 Correct 24 ms 3452 KB Output is correct
6 Correct 25 ms 3372 KB Output is correct
7 Correct 24 ms 3412 KB Output is correct
8 Correct 24 ms 3392 KB Output is correct
9 Correct 24 ms 3448 KB Output is correct
10 Correct 24 ms 3348 KB Output is correct
11 Correct 24 ms 3388 KB Output is correct
12 Correct 24 ms 3412 KB Output is correct
13 Correct 24 ms 3456 KB Output is correct
14 Correct 24 ms 3412 KB Output is correct
15 Correct 25 ms 3392 KB Output is correct
16 Correct 25 ms 3564 KB Output is correct
17 Correct 24 ms 3400 KB Output is correct
18 Correct 24 ms 3376 KB Output is correct
19 Correct 24 ms 3380 KB Output is correct
20 Correct 24 ms 3404 KB Output is correct
21 Correct 24 ms 3392 KB Output is correct
22 Correct 24 ms 3384 KB Output is correct
23 Correct 24 ms 3384 KB Output is correct
24 Correct 24 ms 3404 KB Output is correct
25 Correct 25 ms 3380 KB Output is correct
26 Correct 26 ms 3412 KB Output is correct
27 Correct 25 ms 3384 KB Output is correct
28 Correct 24 ms 3380 KB Output is correct
29 Correct 24 ms 3460 KB Output is correct
30 Correct 24 ms 3372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3348 KB Output is correct
2 Correct 24 ms 3372 KB Output is correct
3 Correct 24 ms 3384 KB Output is correct
4 Correct 24 ms 3412 KB Output is correct
5 Correct 24 ms 3452 KB Output is correct
6 Correct 25 ms 3372 KB Output is correct
7 Correct 24 ms 3412 KB Output is correct
8 Correct 24 ms 3392 KB Output is correct
9 Correct 24 ms 3448 KB Output is correct
10 Correct 24 ms 3348 KB Output is correct
11 Correct 24 ms 3388 KB Output is correct
12 Correct 24 ms 3412 KB Output is correct
13 Correct 24 ms 3456 KB Output is correct
14 Correct 24 ms 3412 KB Output is correct
15 Correct 25 ms 3392 KB Output is correct
16 Correct 25 ms 3564 KB Output is correct
17 Correct 24 ms 3400 KB Output is correct
18 Correct 24 ms 3376 KB Output is correct
19 Correct 24 ms 3380 KB Output is correct
20 Correct 24 ms 3404 KB Output is correct
21 Correct 24 ms 3392 KB Output is correct
22 Correct 24 ms 3384 KB Output is correct
23 Correct 24 ms 3384 KB Output is correct
24 Correct 24 ms 3404 KB Output is correct
25 Correct 25 ms 3380 KB Output is correct
26 Correct 26 ms 3412 KB Output is correct
27 Correct 25 ms 3384 KB Output is correct
28 Correct 24 ms 3380 KB Output is correct
29 Correct 24 ms 3460 KB Output is correct
30 Correct 24 ms 3372 KB Output is correct
31 Correct 24 ms 3380 KB Output is correct
32 Correct 26 ms 3384 KB Output is correct
33 Correct 24 ms 3420 KB Output is correct
34 Correct 28 ms 3428 KB Output is correct
35 Correct 29 ms 3436 KB Output is correct
36 Correct 30 ms 3448 KB Output is correct
37 Correct 30 ms 3444 KB Output is correct
38 Correct 26 ms 3372 KB Output is correct
39 Correct 27 ms 3392 KB Output is correct
40 Correct 28 ms 3420 KB Output is correct