# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
154281 | karma | Asceticism (JOI18_asceticism) | C++14 | 15 ms | 2040 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define Task "test"
#define ll long long
#define pb emplace_back
using namespace std;
const int N = int(1e5) + 5;
const int mod = int(1e9) + 7;
ll f[N], inv[N];
int n, k;
ll Power(ll x, ll y) {
ll res = 1;
while(y) {
if(y & 1) res = res * x % mod;
x = x * x % mod; y >>= 1;
}
return res;
}
int nCk(int n, int k) {return f[n] * inv[k] % mod * inv[n - k] % mod;}
int Eulerian(int n, int k) {
int res = 0;
for(int i = 0; i <= k; ++i) {
if(i & 1) res -= (nCk(n + 1, i) * Power(k + 1 - i, n) % mod);
else res += (nCk(n + 1, i) * Power(k + 1 - i, n) % mod);
if(res < 0) res += mod;
else if(res >= mod) res -= mod;
}
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
if(fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
cin >> n >> k;
f[0] = 1;
for(int i = 1; i <= n + 1; ++i) f[i] = f[i - 1] * i % mod;
inv[n + 1] = Power(f[n + 1], mod - 2);
for(int i = n; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % mod;
cout << Eulerian(n, k - 1);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |