Submission #232547

# Submission time Handle Problem Language Result Execution time Memory
232547 2020-05-17T10:23:33 Z AlexLuchianov Asceticism (JOI18_asceticism) C++14
100 / 100
63 ms 1272 KB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 200000;
int const modulo = 1000000007;

int fact[1 + nmax];

void gcd(int a, int b, int &x, int &y){
  if(b == 0){
    x = 1;
    y = 0;
  } else {
    gcd(b, a % b, x, y);
    int aux = x;
    x = y;
    y = aux - a / b * y;
  }
}

void computefact(){
  fact[0] = 1;
  for(int i = 1; i <= nmax; i++)
    fact[i] = 1LL * fact[i - 1] * i % modulo;
}

int invers(int number){
  int x, y;
  gcd(number, modulo, x, y);
  x %= modulo;
  if(x < 0)
    x += modulo;
  return x;
}

int comb(int n, int k){
  int result = fact[n];
  int result2 = 1LL * fact[k] * fact[n - k] % modulo;
  return 1LL * result * invers(result2) % modulo;
}

int lgpow(int a, int b){
  a = (modulo + a) % modulo;
  if(b == 0)
    return 1;
  else if(b == 1)
    return a;
  else {
    int result = lgpow(a, b / 2);
    if(b % 2 == 0)
      return 1LL * result * result % modulo;
    else
      return 1LL * result * result % modulo * a % modulo;
  }
}

int euler(int n, int m){
  int result = 0;
  for(int i = 0; i <= m; i++){
    result += (1LL * lgpow(-1, i) * comb(n + 1, i) % modulo) * lgpow(m + 1 - i, n) % modulo;
    if(modulo <= result)
      result -= modulo;
  }
  return result;
}

int main()
{
  computefact();
  int n, k;
  cin >> n >> k;
  cout << euler(n, n - k) << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1152 KB Output is correct
2 Correct 6 ms 1152 KB Output is correct
3 Correct 6 ms 1152 KB Output is correct
4 Correct 6 ms 1152 KB Output is correct
5 Correct 6 ms 1152 KB Output is correct
6 Correct 6 ms 1152 KB Output is correct
7 Correct 6 ms 1152 KB Output is correct
8 Correct 6 ms 1152 KB Output is correct
9 Correct 6 ms 1152 KB Output is correct
10 Correct 6 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1152 KB Output is correct
2 Correct 6 ms 1152 KB Output is correct
3 Correct 6 ms 1152 KB Output is correct
4 Correct 6 ms 1152 KB Output is correct
5 Correct 6 ms 1152 KB Output is correct
6 Correct 6 ms 1152 KB Output is correct
7 Correct 6 ms 1152 KB Output is correct
8 Correct 6 ms 1152 KB Output is correct
9 Correct 6 ms 1152 KB Output is correct
10 Correct 6 ms 1152 KB Output is correct
11 Correct 6 ms 1152 KB Output is correct
12 Correct 6 ms 1152 KB Output is correct
13 Correct 6 ms 1152 KB Output is correct
14 Correct 6 ms 1152 KB Output is correct
15 Correct 6 ms 1152 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 6 ms 1152 KB Output is correct
18 Correct 6 ms 1152 KB Output is correct
19 Correct 6 ms 1152 KB Output is correct
20 Correct 6 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1152 KB Output is correct
2 Correct 6 ms 1152 KB Output is correct
3 Correct 6 ms 1152 KB Output is correct
4 Correct 6 ms 1152 KB Output is correct
5 Correct 6 ms 1152 KB Output is correct
6 Correct 6 ms 1152 KB Output is correct
7 Correct 6 ms 1152 KB Output is correct
8 Correct 6 ms 1152 KB Output is correct
9 Correct 6 ms 1152 KB Output is correct
10 Correct 6 ms 1152 KB Output is correct
11 Correct 6 ms 1152 KB Output is correct
12 Correct 6 ms 1152 KB Output is correct
13 Correct 6 ms 1152 KB Output is correct
14 Correct 6 ms 1152 KB Output is correct
15 Correct 6 ms 1152 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 6 ms 1152 KB Output is correct
18 Correct 6 ms 1152 KB Output is correct
19 Correct 6 ms 1152 KB Output is correct
20 Correct 6 ms 1152 KB Output is correct
21 Correct 6 ms 1152 KB Output is correct
22 Correct 6 ms 1152 KB Output is correct
23 Correct 6 ms 1152 KB Output is correct
24 Correct 7 ms 1152 KB Output is correct
25 Correct 6 ms 1152 KB Output is correct
26 Correct 6 ms 1152 KB Output is correct
27 Correct 6 ms 1152 KB Output is correct
28 Correct 6 ms 1152 KB Output is correct
29 Correct 6 ms 1152 KB Output is correct
30 Correct 6 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1152 KB Output is correct
2 Correct 6 ms 1152 KB Output is correct
3 Correct 6 ms 1152 KB Output is correct
4 Correct 6 ms 1152 KB Output is correct
5 Correct 6 ms 1152 KB Output is correct
6 Correct 6 ms 1152 KB Output is correct
7 Correct 6 ms 1152 KB Output is correct
8 Correct 6 ms 1152 KB Output is correct
9 Correct 6 ms 1152 KB Output is correct
10 Correct 6 ms 1152 KB Output is correct
11 Correct 6 ms 1152 KB Output is correct
12 Correct 6 ms 1152 KB Output is correct
13 Correct 6 ms 1152 KB Output is correct
14 Correct 6 ms 1152 KB Output is correct
15 Correct 6 ms 1152 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 6 ms 1152 KB Output is correct
18 Correct 6 ms 1152 KB Output is correct
19 Correct 6 ms 1152 KB Output is correct
20 Correct 6 ms 1152 KB Output is correct
21 Correct 6 ms 1152 KB Output is correct
22 Correct 6 ms 1152 KB Output is correct
23 Correct 6 ms 1152 KB Output is correct
24 Correct 7 ms 1152 KB Output is correct
25 Correct 6 ms 1152 KB Output is correct
26 Correct 6 ms 1152 KB Output is correct
27 Correct 6 ms 1152 KB Output is correct
28 Correct 6 ms 1152 KB Output is correct
29 Correct 6 ms 1152 KB Output is correct
30 Correct 6 ms 1152 KB Output is correct
31 Correct 63 ms 1144 KB Output is correct
32 Correct 63 ms 1144 KB Output is correct
33 Correct 59 ms 1272 KB Output is correct
34 Correct 54 ms 1152 KB Output is correct
35 Correct 15 ms 1152 KB Output is correct
36 Correct 10 ms 1152 KB Output is correct
37 Correct 6 ms 1152 KB Output is correct
38 Correct 8 ms 1152 KB Output is correct
39 Correct 27 ms 1152 KB Output is correct
40 Correct 39 ms 1144 KB Output is correct