Submission #232546

# Submission time Handle Problem Language Result Execution time Memory
232546 2020-05-17T10:23:03 Z AlexLuchianov Asceticism (JOI18_asceticism) C++14
49 / 100
61 ms 896 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 = 100000;
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 5 ms 640 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 640 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 6 ms 896 KB Output is correct
10 Correct 5 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 640 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 6 ms 896 KB Output is correct
10 Correct 5 ms 768 KB Output is correct
11 Correct 5 ms 768 KB Output is correct
12 Correct 5 ms 768 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 5 ms 768 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 6 ms 768 KB Output is correct
18 Correct 5 ms 640 KB Output is correct
19 Correct 5 ms 640 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 640 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 6 ms 896 KB Output is correct
10 Correct 5 ms 768 KB Output is correct
11 Correct 5 ms 768 KB Output is correct
12 Correct 5 ms 768 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 5 ms 768 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 6 ms 768 KB Output is correct
18 Correct 5 ms 640 KB Output is correct
19 Correct 5 ms 640 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
21 Correct 6 ms 768 KB Output is correct
22 Correct 6 ms 768 KB Output is correct
23 Correct 6 ms 768 KB Output is correct
24 Correct 6 ms 768 KB Output is correct
25 Correct 5 ms 640 KB Output is correct
26 Correct 5 ms 768 KB Output is correct
27 Correct 6 ms 768 KB Output is correct
28 Correct 5 ms 640 KB Output is correct
29 Correct 6 ms 640 KB Output is correct
30 Correct 5 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 640 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 6 ms 896 KB Output is correct
10 Correct 5 ms 768 KB Output is correct
11 Correct 5 ms 768 KB Output is correct
12 Correct 5 ms 768 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 5 ms 768 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 6 ms 768 KB Output is correct
18 Correct 5 ms 640 KB Output is correct
19 Correct 5 ms 640 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
21 Correct 6 ms 768 KB Output is correct
22 Correct 6 ms 768 KB Output is correct
23 Correct 6 ms 768 KB Output is correct
24 Correct 6 ms 768 KB Output is correct
25 Correct 5 ms 640 KB Output is correct
26 Correct 5 ms 768 KB Output is correct
27 Correct 6 ms 768 KB Output is correct
28 Correct 5 ms 640 KB Output is correct
29 Correct 6 ms 640 KB Output is correct
30 Correct 5 ms 768 KB Output is correct
31 Incorrect 61 ms 752 KB Output isn't correct
32 Halted 0 ms 0 KB -