Submission #47477

# Submission time Handle Problem Language Result Execution time Memory
47477 2018-05-03T15:18:12 Z mirbek01 Asceticism (JOI18_asceticism) C++17
100 / 100
30 ms 2172 KB
# include <bits/stdc++.h>

using namespace std;

const long long mod = 1e9 + 7;
const long long N = 1e5 + 2;

long long binpow(long long a, long long n){
      long long res = 1;
      while(n){
            if(n & 1)
                  res = (res * a) % mod;
            a = (a * a) % mod;
            n >>= 1;
      }
      return res;
}

long long n, k, f[N], fi[N];

long long cnk(long long n, long long k){
      return ((f[n] * fi[n - k]) % mod * fi[k]) % mod;
}


int main(){
      f[0] = 1;
      fi[0] = binpow(f[0], mod - 2);

      for(long long i = 1; i < N; i ++){
            f[i] = (f[i - 1] * i) % mod;
            fi[i] = binpow(f[i], mod - 2);
      }

      cin >> n >> k;

      long long ans = 0;

      for(long long i = 0; i <= k; i ++){
            if(i & 1){
                  ans -= (cnk(n + 1, i) * binpow(k - i, n)) % mod;
                  if(ans < 0) ans += mod;
            } else {
                  ans += (cnk(n + 1, i) * binpow(k - i, n)) % mod;
                  if(ans > mod) ans -= mod;
            }
      }

      cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1912 KB Output is correct
2 Correct 20 ms 2024 KB Output is correct
3 Correct 20 ms 2024 KB Output is correct
4 Correct 20 ms 2024 KB Output is correct
5 Correct 19 ms 2024 KB Output is correct
6 Correct 19 ms 2128 KB Output is correct
7 Correct 20 ms 2128 KB Output is correct
8 Correct 19 ms 2128 KB Output is correct
9 Correct 19 ms 2128 KB Output is correct
10 Correct 20 ms 2128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1912 KB Output is correct
2 Correct 20 ms 2024 KB Output is correct
3 Correct 20 ms 2024 KB Output is correct
4 Correct 20 ms 2024 KB Output is correct
5 Correct 19 ms 2024 KB Output is correct
6 Correct 19 ms 2128 KB Output is correct
7 Correct 20 ms 2128 KB Output is correct
8 Correct 19 ms 2128 KB Output is correct
9 Correct 19 ms 2128 KB Output is correct
10 Correct 20 ms 2128 KB Output is correct
11 Correct 19 ms 2128 KB Output is correct
12 Correct 19 ms 2128 KB Output is correct
13 Correct 20 ms 2128 KB Output is correct
14 Correct 19 ms 2128 KB Output is correct
15 Correct 19 ms 2128 KB Output is correct
16 Correct 22 ms 2128 KB Output is correct
17 Correct 20 ms 2128 KB Output is correct
18 Correct 19 ms 2144 KB Output is correct
19 Correct 19 ms 2148 KB Output is correct
20 Correct 19 ms 2148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1912 KB Output is correct
2 Correct 20 ms 2024 KB Output is correct
3 Correct 20 ms 2024 KB Output is correct
4 Correct 20 ms 2024 KB Output is correct
5 Correct 19 ms 2024 KB Output is correct
6 Correct 19 ms 2128 KB Output is correct
7 Correct 20 ms 2128 KB Output is correct
8 Correct 19 ms 2128 KB Output is correct
9 Correct 19 ms 2128 KB Output is correct
10 Correct 20 ms 2128 KB Output is correct
11 Correct 19 ms 2128 KB Output is correct
12 Correct 19 ms 2128 KB Output is correct
13 Correct 20 ms 2128 KB Output is correct
14 Correct 19 ms 2128 KB Output is correct
15 Correct 19 ms 2128 KB Output is correct
16 Correct 22 ms 2128 KB Output is correct
17 Correct 20 ms 2128 KB Output is correct
18 Correct 19 ms 2144 KB Output is correct
19 Correct 19 ms 2148 KB Output is correct
20 Correct 19 ms 2148 KB Output is correct
21 Correct 19 ms 2148 KB Output is correct
22 Correct 21 ms 2148 KB Output is correct
23 Correct 20 ms 2148 KB Output is correct
24 Correct 19 ms 2148 KB Output is correct
25 Correct 20 ms 2148 KB Output is correct
26 Correct 20 ms 2148 KB Output is correct
27 Correct 20 ms 2148 KB Output is correct
28 Correct 19 ms 2148 KB Output is correct
29 Correct 19 ms 2148 KB Output is correct
30 Correct 19 ms 2148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1912 KB Output is correct
2 Correct 20 ms 2024 KB Output is correct
3 Correct 20 ms 2024 KB Output is correct
4 Correct 20 ms 2024 KB Output is correct
5 Correct 19 ms 2024 KB Output is correct
6 Correct 19 ms 2128 KB Output is correct
7 Correct 20 ms 2128 KB Output is correct
8 Correct 19 ms 2128 KB Output is correct
9 Correct 19 ms 2128 KB Output is correct
10 Correct 20 ms 2128 KB Output is correct
11 Correct 19 ms 2128 KB Output is correct
12 Correct 19 ms 2128 KB Output is correct
13 Correct 20 ms 2128 KB Output is correct
14 Correct 19 ms 2128 KB Output is correct
15 Correct 19 ms 2128 KB Output is correct
16 Correct 22 ms 2128 KB Output is correct
17 Correct 20 ms 2128 KB Output is correct
18 Correct 19 ms 2144 KB Output is correct
19 Correct 19 ms 2148 KB Output is correct
20 Correct 19 ms 2148 KB Output is correct
21 Correct 19 ms 2148 KB Output is correct
22 Correct 21 ms 2148 KB Output is correct
23 Correct 20 ms 2148 KB Output is correct
24 Correct 19 ms 2148 KB Output is correct
25 Correct 20 ms 2148 KB Output is correct
26 Correct 20 ms 2148 KB Output is correct
27 Correct 20 ms 2148 KB Output is correct
28 Correct 19 ms 2148 KB Output is correct
29 Correct 19 ms 2148 KB Output is correct
30 Correct 19 ms 2148 KB Output is correct
31 Correct 20 ms 2148 KB Output is correct
32 Correct 20 ms 2148 KB Output is correct
33 Correct 20 ms 2148 KB Output is correct
34 Correct 20 ms 2148 KB Output is correct
35 Correct 27 ms 2148 KB Output is correct
36 Correct 28 ms 2148 KB Output is correct
37 Correct 30 ms 2148 KB Output is correct
38 Correct 20 ms 2148 KB Output is correct
39 Correct 22 ms 2156 KB Output is correct
40 Correct 23 ms 2172 KB Output is correct