Submission #151808

#TimeUsernameProblemLanguageResultExecution timeMemory
151808osaaateiasavtnlAsceticism (JOI18_asceticism)C++14
100 / 100
29 ms1272 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ii pair <int, int> #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcount #define ll long long #define mp make_pair #define f first #define s second const int N = 1e5 + 7, MOD = 1000 * 1000 * 1000 + 7; int mod(int n) { return (n % MOD + MOD) % MOD; } int fp(int a, int p) { int ans = 1, cur = a; for (int i = 0; (1ll << i) <= p; ++i) { if ((p >> i) & 1) ans = (ans * cur) % MOD; cur = (cur * cur) % MOD; } return ans; } int inv(int x) { return fp(x, MOD - 2); } int dv(int a, int b) { return (a * inv(b)) % MOD; } int f[N]; int C(int n, int k) { return dv(f[n], (f[n - k] * f[k]) % MOD); } int eulerian(int n, int m) { int ans = 0; for (int k = 0; k <= m; ++k) { if (k & 1) ans -= (C(n + 1, k) * fp(m + 1 - k, n)) % MOD; else ans += (C(n + 1, k) * fp(m + 1 - k, n)) % MOD; } return mod(ans); } signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else ios_base::sync_with_stdio(0); cin.tie(0); #endif f[0] = 1; for (int i = 1; i < N; ++i) f[i] = (f[i - 1] * i) % MOD; int n, k; cin >> n >> k; cout << eulerian(n, k - 1) << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...