Submission #77386

# Submission time Handle Problem Language Result Execution time Memory
77386 2018-09-27T10:09:11 Z tmwilliamlin168 Asceticism (JOI18_asceticism) C++14
100 / 100
38 ms 1864 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int mxN=1e5, M=1e9+7;
int n, k;
ll fi[mxN+1], ans;

ll exp(ll b, int p) {
	ll r=1;
	while(p) {
		if(p&1)
			r=b*r%M;
		b=b*b%M;
		p/=2;
	}
	return r;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	fi[0]=1;
	for(int i=1; i<=n; ++i)
		fi[i]=exp(i, M-2)*fi[i-1]%M;
	for(int j=0; j<=1; ++j)
		for(int i=0; i<k-j; ++i)
			ans+=(i&1^j?M-1:1)*exp(k-j-i, n)%M*fi[i]%M*fi[n-i]%M;
	for(int i=2; i<=n; ++i)
		ans=i*ans%M;
	cout << ans;
}

Compilation message

asceticism.cpp: In function 'int main()':
asceticism.cpp:31:11: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
    ans+=(i&1^j?M-1:1)*exp(k-j-i, n)%M*fi[i]%M*fi[n-i]%M;
          ~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 684 KB Output is correct
3 Correct 2 ms 684 KB Output is correct
4 Correct 2 ms 684 KB Output is correct
5 Correct 2 ms 716 KB Output is correct
6 Correct 2 ms 720 KB Output is correct
7 Correct 2 ms 872 KB Output is correct
8 Correct 2 ms 960 KB Output is correct
9 Correct 2 ms 960 KB Output is correct
10 Correct 2 ms 960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 684 KB Output is correct
3 Correct 2 ms 684 KB Output is correct
4 Correct 2 ms 684 KB Output is correct
5 Correct 2 ms 716 KB Output is correct
6 Correct 2 ms 720 KB Output is correct
7 Correct 2 ms 872 KB Output is correct
8 Correct 2 ms 960 KB Output is correct
9 Correct 2 ms 960 KB Output is correct
10 Correct 2 ms 960 KB Output is correct
11 Correct 2 ms 960 KB Output is correct
12 Correct 2 ms 960 KB Output is correct
13 Correct 2 ms 960 KB Output is correct
14 Correct 2 ms 960 KB Output is correct
15 Correct 2 ms 960 KB Output is correct
16 Correct 2 ms 960 KB Output is correct
17 Correct 2 ms 960 KB Output is correct
18 Correct 2 ms 960 KB Output is correct
19 Correct 2 ms 960 KB Output is correct
20 Correct 3 ms 1044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 684 KB Output is correct
3 Correct 2 ms 684 KB Output is correct
4 Correct 2 ms 684 KB Output is correct
5 Correct 2 ms 716 KB Output is correct
6 Correct 2 ms 720 KB Output is correct
7 Correct 2 ms 872 KB Output is correct
8 Correct 2 ms 960 KB Output is correct
9 Correct 2 ms 960 KB Output is correct
10 Correct 2 ms 960 KB Output is correct
11 Correct 2 ms 960 KB Output is correct
12 Correct 2 ms 960 KB Output is correct
13 Correct 2 ms 960 KB Output is correct
14 Correct 2 ms 960 KB Output is correct
15 Correct 2 ms 960 KB Output is correct
16 Correct 2 ms 960 KB Output is correct
17 Correct 2 ms 960 KB Output is correct
18 Correct 2 ms 960 KB Output is correct
19 Correct 2 ms 960 KB Output is correct
20 Correct 3 ms 1044 KB Output is correct
21 Correct 3 ms 1044 KB Output is correct
22 Correct 2 ms 1044 KB Output is correct
23 Correct 2 ms 1044 KB Output is correct
24 Correct 2 ms 1044 KB Output is correct
25 Correct 2 ms 1044 KB Output is correct
26 Correct 2 ms 1044 KB Output is correct
27 Correct 2 ms 1044 KB Output is correct
28 Correct 2 ms 1044 KB Output is correct
29 Correct 2 ms 1044 KB Output is correct
30 Correct 2 ms 1044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 684 KB Output is correct
3 Correct 2 ms 684 KB Output is correct
4 Correct 2 ms 684 KB Output is correct
5 Correct 2 ms 716 KB Output is correct
6 Correct 2 ms 720 KB Output is correct
7 Correct 2 ms 872 KB Output is correct
8 Correct 2 ms 960 KB Output is correct
9 Correct 2 ms 960 KB Output is correct
10 Correct 2 ms 960 KB Output is correct
11 Correct 2 ms 960 KB Output is correct
12 Correct 2 ms 960 KB Output is correct
13 Correct 2 ms 960 KB Output is correct
14 Correct 2 ms 960 KB Output is correct
15 Correct 2 ms 960 KB Output is correct
16 Correct 2 ms 960 KB Output is correct
17 Correct 2 ms 960 KB Output is correct
18 Correct 2 ms 960 KB Output is correct
19 Correct 2 ms 960 KB Output is correct
20 Correct 3 ms 1044 KB Output is correct
21 Correct 3 ms 1044 KB Output is correct
22 Correct 2 ms 1044 KB Output is correct
23 Correct 2 ms 1044 KB Output is correct
24 Correct 2 ms 1044 KB Output is correct
25 Correct 2 ms 1044 KB Output is correct
26 Correct 2 ms 1044 KB Output is correct
27 Correct 2 ms 1044 KB Output is correct
28 Correct 2 ms 1044 KB Output is correct
29 Correct 2 ms 1044 KB Output is correct
30 Correct 2 ms 1044 KB Output is correct
31 Correct 20 ms 1756 KB Output is correct
32 Correct 21 ms 1864 KB Output is correct
33 Correct 21 ms 1864 KB Output is correct
34 Correct 23 ms 1864 KB Output is correct
35 Correct 35 ms 1864 KB Output is correct
36 Correct 36 ms 1864 KB Output is correct
37 Correct 38 ms 1864 KB Output is correct
38 Correct 7 ms 1864 KB Output is correct
39 Correct 20 ms 1864 KB Output is correct
40 Correct 29 ms 1864 KB Output is correct