답안 #151808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151808 2019-09-04T21:38:00 Z osaaateiasavtnl Asceticism (JOI18_asceticism) C++14
100 / 100
29 ms 1272 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
const int N = 1e5 + 7, MOD = 1000 * 1000 * 1000 + 7;
int mod(int n) { return (n % MOD + MOD) % MOD; }
int fp(int a, int p) {
    int ans = 1, cur = a;
    for (int i = 0; (1ll << i) <= p; ++i) {
        if ((p >> i) & 1) ans = (ans * cur) % MOD;
        cur = (cur * cur) % MOD;
    }   
    return ans;
}   
int inv(int x) { return fp(x, MOD - 2); }
int dv(int a, int b) { return (a * inv(b)) % MOD; }
int f[N];
int C(int n, int k) { return dv(f[n], (f[n - k] * f[k]) % MOD); }
int eulerian(int n, int m) {
    int ans = 0;
    for (int k = 0; k <= m; ++k) {
        if (k & 1) ans -= (C(n + 1, k) * fp(m + 1 - k, n)) % MOD;
        else ans += (C(n + 1, k) * fp(m + 1 - k, n)) % MOD;
    }   
    return mod(ans);
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    f[0] = 1;
    for (int i = 1; i < N; ++i) f[i] = (f[i - 1] * i) % MOD;
    int n, k;
    cin >> n >> k;
    cout << eulerian(n, k - 1) << '\n';                
}   
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1144 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1144 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 4 ms 1144 KB Output is correct
15 Correct 4 ms 1148 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 3 ms 1144 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 4 ms 1144 KB Output is correct
20 Correct 3 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1144 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1144 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 4 ms 1144 KB Output is correct
15 Correct 4 ms 1148 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 3 ms 1144 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 4 ms 1144 KB Output is correct
20 Correct 3 ms 1144 KB Output is correct
21 Correct 4 ms 1144 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 4 ms 1144 KB Output is correct
24 Correct 4 ms 1144 KB Output is correct
25 Correct 4 ms 1144 KB Output is correct
26 Correct 3 ms 1140 KB Output is correct
27 Correct 4 ms 1192 KB Output is correct
28 Correct 3 ms 1144 KB Output is correct
29 Correct 4 ms 1148 KB Output is correct
30 Correct 4 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1144 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1144 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 4 ms 1144 KB Output is correct
15 Correct 4 ms 1148 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 3 ms 1144 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 4 ms 1144 KB Output is correct
20 Correct 3 ms 1144 KB Output is correct
21 Correct 4 ms 1144 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 4 ms 1144 KB Output is correct
24 Correct 4 ms 1144 KB Output is correct
25 Correct 4 ms 1144 KB Output is correct
26 Correct 3 ms 1140 KB Output is correct
27 Correct 4 ms 1192 KB Output is correct
28 Correct 3 ms 1144 KB Output is correct
29 Correct 4 ms 1148 KB Output is correct
30 Correct 4 ms 1144 KB Output is correct
31 Correct 3 ms 1164 KB Output is correct
32 Correct 3 ms 1144 KB Output is correct
33 Correct 5 ms 1144 KB Output is correct
34 Correct 7 ms 1144 KB Output is correct
35 Correct 24 ms 1144 KB Output is correct
36 Correct 27 ms 1144 KB Output is correct
37 Correct 29 ms 1272 KB Output is correct
38 Correct 6 ms 1144 KB Output is correct
39 Correct 11 ms 1144 KB Output is correct
40 Correct 14 ms 1272 KB Output is correct