Submission #1322429

#TimeUsernameProblemLanguageResultExecution timeMemory
1322429kizuAsceticism (JOI18_asceticism)C++20
100 / 100
7 ms1848 KiB
#include <bits/stdc++.h> using namespace std ; #define ll long long #define is == #define isnt != #define wnsl '\n' const ll mod = 1000000007 ; ll modpow (ll a, ll e) { a %= mod ; ll r = 1 ; while (e > 0) { if (e & 1) r = (r * a) % mod ; a = (a * a) % mod ; e >>= 1 ; } return r ; } ll modinv (ll a) { return modpow (a, mod - 2) ; } int main () { ios::sync_with_stdio (false) ; cin.tie (nullptr) ; ll N, K ; cin >> N >> K ; vector<ll> fact (N + 2), invfact (N + 2) ; fact[0] = 1 ; for (ll i = 1; i <= N + 1; i++) fact[i] = (fact[i - 1] * i) % mod ; invfact[N + 1] = modinv (fact[N + 1]) ; for (ll i = N + 1; i >= 1; i--) invfact[i - 1] = (invfact[i] * i) % mod ; auto C = [&] (ll n, ll r) -> ll { if (r < 0 or r > n) return 0 ; return (((fact[n] * invfact[r]) % mod) * invfact[n - r]) % mod ; } ; ll ans = 0 ; for (ll j = 0; j <= K; j++) { ll comb = C (N + 1, j) ; ll base = K - j ; ll pw = modpow (base, N) ; ll term = (comb * pw) % mod ; if (j & 1) ans = (ans - term + mod) % mod ; else ans = (ans + term) % mod ; } cout << ans << wnsl ; return 0 ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...