Submission #305542

# Submission time Handle Problem Language Result Execution time Memory
305542 2020-09-23T13:39:00 Z quocnguyen1012 Asceticism (JOI18_asceticism) C++14
100 / 100
21 ms 1152 KB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int mod = 1e9 + 7, maxn = 1e5 + 5;

int fact[maxn], ifact[maxn];
int N, K;

int power(int a, int b) {
  if (b == 0) return 1;
  int res = power(a, b / 2);
  if (b & 1) return (ll)res * res % mod * a % mod;
  return (ll)res * res % mod;
}

int inv(int a) {
  return power(a, mod - 2);
}

int binom(int k, int n) {
  if (k < 0 || n < 0 || k > n) return 0;
  return (ll)fact[n] * ifact[k] % mod * ifact[n - k] % mod;
}

void add(int & x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  if (x < 0) x += mod;
}

signed main(void) {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL

  fact[0] = 1;
  for (int i = 1; i < maxn; ++i) {
    fact[i] = (ll)fact[i - 1] * i % mod;
  }
  ifact[maxn - 1] = inv(fact[maxn - 1]);
  for (int i = maxn - 2; i >= 0; --i) {
    ifact[i] = (ll)ifact[i + 1] * (i + 1) % mod;
  }

  cin >> N >> K;
  int res = 0;
  for (int i = 0; i <= K; ++i) {
    int sign = 1;
    if (i & 1) sign = -1;
    int way = (ll)power(K - i, N) * binom(i, N + 1) % mod;
    ///cerr << way << '\n';
    add(res, sign * way);
  }
  cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1152 KB Output is correct
2 Correct 2 ms 1152 KB Output is correct
3 Correct 2 ms 1152 KB Output is correct
4 Correct 2 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 2 ms 1152 KB Output is correct
7 Correct 2 ms 1152 KB Output is correct
8 Correct 3 ms 1152 KB Output is correct
9 Correct 2 ms 1152 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1152 KB Output is correct
2 Correct 2 ms 1152 KB Output is correct
3 Correct 2 ms 1152 KB Output is correct
4 Correct 2 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 2 ms 1152 KB Output is correct
7 Correct 2 ms 1152 KB Output is correct
8 Correct 3 ms 1152 KB Output is correct
9 Correct 2 ms 1152 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 2 ms 1152 KB Output is correct
13 Correct 2 ms 1152 KB Output is correct
14 Correct 3 ms 1152 KB Output is correct
15 Correct 3 ms 1152 KB Output is correct
16 Correct 3 ms 1152 KB Output is correct
17 Correct 2 ms 1152 KB Output is correct
18 Correct 3 ms 1056 KB Output is correct
19 Correct 3 ms 1152 KB Output is correct
20 Correct 3 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1152 KB Output is correct
2 Correct 2 ms 1152 KB Output is correct
3 Correct 2 ms 1152 KB Output is correct
4 Correct 2 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 2 ms 1152 KB Output is correct
7 Correct 2 ms 1152 KB Output is correct
8 Correct 3 ms 1152 KB Output is correct
9 Correct 2 ms 1152 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 2 ms 1152 KB Output is correct
13 Correct 2 ms 1152 KB Output is correct
14 Correct 3 ms 1152 KB Output is correct
15 Correct 3 ms 1152 KB Output is correct
16 Correct 3 ms 1152 KB Output is correct
17 Correct 2 ms 1152 KB Output is correct
18 Correct 3 ms 1056 KB Output is correct
19 Correct 3 ms 1152 KB Output is correct
20 Correct 3 ms 1152 KB Output is correct
21 Correct 3 ms 1152 KB Output is correct
22 Correct 3 ms 1152 KB Output is correct
23 Correct 3 ms 1152 KB Output is correct
24 Correct 3 ms 1152 KB Output is correct
25 Correct 3 ms 1152 KB Output is correct
26 Correct 3 ms 1152 KB Output is correct
27 Correct 3 ms 1152 KB Output is correct
28 Correct 3 ms 1152 KB Output is correct
29 Correct 2 ms 1152 KB Output is correct
30 Correct 3 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1152 KB Output is correct
2 Correct 2 ms 1152 KB Output is correct
3 Correct 2 ms 1152 KB Output is correct
4 Correct 2 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 2 ms 1152 KB Output is correct
7 Correct 2 ms 1152 KB Output is correct
8 Correct 3 ms 1152 KB Output is correct
9 Correct 2 ms 1152 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 2 ms 1152 KB Output is correct
13 Correct 2 ms 1152 KB Output is correct
14 Correct 3 ms 1152 KB Output is correct
15 Correct 3 ms 1152 KB Output is correct
16 Correct 3 ms 1152 KB Output is correct
17 Correct 2 ms 1152 KB Output is correct
18 Correct 3 ms 1056 KB Output is correct
19 Correct 3 ms 1152 KB Output is correct
20 Correct 3 ms 1152 KB Output is correct
21 Correct 3 ms 1152 KB Output is correct
22 Correct 3 ms 1152 KB Output is correct
23 Correct 3 ms 1152 KB Output is correct
24 Correct 3 ms 1152 KB Output is correct
25 Correct 3 ms 1152 KB Output is correct
26 Correct 3 ms 1152 KB Output is correct
27 Correct 3 ms 1152 KB Output is correct
28 Correct 3 ms 1152 KB Output is correct
29 Correct 2 ms 1152 KB Output is correct
30 Correct 3 ms 1152 KB Output is correct
31 Correct 3 ms 1152 KB Output is correct
32 Correct 2 ms 1152 KB Output is correct
33 Correct 3 ms 1152 KB Output is correct
34 Correct 5 ms 1152 KB Output is correct
35 Correct 18 ms 1152 KB Output is correct
36 Correct 19 ms 1152 KB Output is correct
37 Correct 21 ms 1152 KB Output is correct
38 Correct 5 ms 1056 KB Output is correct
39 Correct 8 ms 1152 KB Output is correct
40 Correct 10 ms 1152 KB Output is correct