# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
411092 |
2021-05-24T10:51:57 Z |
반딧불(#7588) |
Asceticism (JOI18_asceticism) |
C++17 |
|
600 ms |
1996 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
ll mpow(ll x, ll y){
if(!y) return 1;
if(y&1) return mpow(x, y-1) * x % MOD;
ll tmp = mpow(x, y/2);
return tmp * tmp % MOD;
}
ll n, k;
ll fact[100002], factInv[100002];
ll DP[100002];
ll ans;
ll comb(ll x, ll y){
return fact[x] * factInv[y] % MOD * factInv[x-y] % MOD;
}
int main(){
fact[0] = 1;
for(int i=1; i<=100000; i++) fact[i] = fact[i-1] * i % MOD;
factInv[100000] = mpow(fact[100000], MOD-2);
for(int i=99999; i>=0; i--) factInv[i] = factInv[i+1] * (i+1) % MOD;
scanf("%lld %lld", &n, &k);
DP[1] = 1;
for(int i=2; i<=k; i++){
for(int j=i; j>0; j--){
if((i-j)%2==0) DP[i] = (DP[i] + comb(i, j) * mpow(j, n)) % MOD;
else DP[i] = (DP[i] + (MOD - comb(i, j)) * mpow(j, n)) % MOD;
}
}
ans = DP[k];
for(int i=k-1; i>=1; i--){
ll weight = comb(n-i, k-i);
if((k-i)%2==0) ans = (ans + weight * DP[i]) % MOD;
else ans = (ans + (MOD - weight) * DP[i]) % MOD;
}
printf("%lld", ans);
}
Compilation message
asceticism.cpp: In function 'int main()':
asceticism.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | scanf("%lld %lld", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1740 KB |
Output is correct |
2 |
Correct |
3 ms |
1868 KB |
Output is correct |
3 |
Correct |
3 ms |
1868 KB |
Output is correct |
4 |
Correct |
3 ms |
1740 KB |
Output is correct |
5 |
Correct |
3 ms |
1868 KB |
Output is correct |
6 |
Correct |
3 ms |
1740 KB |
Output is correct |
7 |
Correct |
3 ms |
1868 KB |
Output is correct |
8 |
Correct |
3 ms |
1868 KB |
Output is correct |
9 |
Correct |
3 ms |
1868 KB |
Output is correct |
10 |
Correct |
3 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1740 KB |
Output is correct |
2 |
Correct |
3 ms |
1868 KB |
Output is correct |
3 |
Correct |
3 ms |
1868 KB |
Output is correct |
4 |
Correct |
3 ms |
1740 KB |
Output is correct |
5 |
Correct |
3 ms |
1868 KB |
Output is correct |
6 |
Correct |
3 ms |
1740 KB |
Output is correct |
7 |
Correct |
3 ms |
1868 KB |
Output is correct |
8 |
Correct |
3 ms |
1868 KB |
Output is correct |
9 |
Correct |
3 ms |
1868 KB |
Output is correct |
10 |
Correct |
3 ms |
1868 KB |
Output is correct |
11 |
Correct |
3 ms |
1740 KB |
Output is correct |
12 |
Correct |
3 ms |
1868 KB |
Output is correct |
13 |
Correct |
3 ms |
1872 KB |
Output is correct |
14 |
Correct |
3 ms |
1868 KB |
Output is correct |
15 |
Correct |
6 ms |
1868 KB |
Output is correct |
16 |
Correct |
6 ms |
1868 KB |
Output is correct |
17 |
Correct |
3 ms |
1868 KB |
Output is correct |
18 |
Correct |
4 ms |
1868 KB |
Output is correct |
19 |
Correct |
4 ms |
1868 KB |
Output is correct |
20 |
Correct |
4 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1740 KB |
Output is correct |
2 |
Correct |
3 ms |
1868 KB |
Output is correct |
3 |
Correct |
3 ms |
1868 KB |
Output is correct |
4 |
Correct |
3 ms |
1740 KB |
Output is correct |
5 |
Correct |
3 ms |
1868 KB |
Output is correct |
6 |
Correct |
3 ms |
1740 KB |
Output is correct |
7 |
Correct |
3 ms |
1868 KB |
Output is correct |
8 |
Correct |
3 ms |
1868 KB |
Output is correct |
9 |
Correct |
3 ms |
1868 KB |
Output is correct |
10 |
Correct |
3 ms |
1868 KB |
Output is correct |
11 |
Correct |
3 ms |
1740 KB |
Output is correct |
12 |
Correct |
3 ms |
1868 KB |
Output is correct |
13 |
Correct |
3 ms |
1872 KB |
Output is correct |
14 |
Correct |
3 ms |
1868 KB |
Output is correct |
15 |
Correct |
6 ms |
1868 KB |
Output is correct |
16 |
Correct |
6 ms |
1868 KB |
Output is correct |
17 |
Correct |
3 ms |
1868 KB |
Output is correct |
18 |
Correct |
4 ms |
1868 KB |
Output is correct |
19 |
Correct |
4 ms |
1868 KB |
Output is correct |
20 |
Correct |
4 ms |
1868 KB |
Output is correct |
21 |
Correct |
3 ms |
1868 KB |
Output is correct |
22 |
Correct |
3 ms |
1868 KB |
Output is correct |
23 |
Correct |
13 ms |
1876 KB |
Output is correct |
24 |
Correct |
14 ms |
1880 KB |
Output is correct |
25 |
Correct |
45 ms |
1868 KB |
Output is correct |
26 |
Correct |
51 ms |
1868 KB |
Output is correct |
27 |
Correct |
48 ms |
1868 KB |
Output is correct |
28 |
Correct |
18 ms |
1876 KB |
Output is correct |
29 |
Correct |
3 ms |
1868 KB |
Output is correct |
30 |
Correct |
50 ms |
1864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1740 KB |
Output is correct |
2 |
Correct |
3 ms |
1868 KB |
Output is correct |
3 |
Correct |
3 ms |
1868 KB |
Output is correct |
4 |
Correct |
3 ms |
1740 KB |
Output is correct |
5 |
Correct |
3 ms |
1868 KB |
Output is correct |
6 |
Correct |
3 ms |
1740 KB |
Output is correct |
7 |
Correct |
3 ms |
1868 KB |
Output is correct |
8 |
Correct |
3 ms |
1868 KB |
Output is correct |
9 |
Correct |
3 ms |
1868 KB |
Output is correct |
10 |
Correct |
3 ms |
1868 KB |
Output is correct |
11 |
Correct |
3 ms |
1740 KB |
Output is correct |
12 |
Correct |
3 ms |
1868 KB |
Output is correct |
13 |
Correct |
3 ms |
1872 KB |
Output is correct |
14 |
Correct |
3 ms |
1868 KB |
Output is correct |
15 |
Correct |
6 ms |
1868 KB |
Output is correct |
16 |
Correct |
6 ms |
1868 KB |
Output is correct |
17 |
Correct |
3 ms |
1868 KB |
Output is correct |
18 |
Correct |
4 ms |
1868 KB |
Output is correct |
19 |
Correct |
4 ms |
1868 KB |
Output is correct |
20 |
Correct |
4 ms |
1868 KB |
Output is correct |
21 |
Correct |
3 ms |
1868 KB |
Output is correct |
22 |
Correct |
3 ms |
1868 KB |
Output is correct |
23 |
Correct |
13 ms |
1876 KB |
Output is correct |
24 |
Correct |
14 ms |
1880 KB |
Output is correct |
25 |
Correct |
45 ms |
1868 KB |
Output is correct |
26 |
Correct |
51 ms |
1868 KB |
Output is correct |
27 |
Correct |
48 ms |
1868 KB |
Output is correct |
28 |
Correct |
18 ms |
1876 KB |
Output is correct |
29 |
Correct |
3 ms |
1868 KB |
Output is correct |
30 |
Correct |
50 ms |
1864 KB |
Output is correct |
31 |
Correct |
3 ms |
1868 KB |
Output is correct |
32 |
Correct |
3 ms |
1868 KB |
Output is correct |
33 |
Execution timed out |
1078 ms |
1996 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |