# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
530518 | Killer2501 | Asceticism (JOI18_asceticism) | C++14 | 12 ms | 6604 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 ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 1e5+5;
const int M = 1e2+2;
const int mod = 1e9+7;
const ll base = 75;
const int inf = 1e9;
int m, n, t, b[N], d[N], lab[N], q;
int k, a[N], dp[N];
ll ans, tong;
vector<int> adj[N];
vector<pii> vi;
string s[N];
bool vis[N];
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n&1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
void add(int &x, int y)
{
x += y;
if(x >= mod)x -= mod;
}
int findp(int u)
{
return lab[u] < 0 ? u : lab[u] = findp(lab[u]);
}
void hop(int u, int v)
{
u = findp(u);
v = findp(v);
if(u == v)return;
if(lab[u] > lab[v])swap(u, v);
lab[u] += lab[v];
lab[v] = u;
}
int C(int u, int v)
{
if(u > v)return 0;
return 1ll * a[v] * b[u] % mod * b[v-u] % mod;
}
void sol()
{
cin >> n >> k;
a[0] = b[0] = 1;
for(int i = 1; i <= n+1; i ++)
a[i] = 1ll * a[i-1] * i % mod;
b[n+1] = pw(a[n+1], mod-2);
for(int i = n; i > 0; i --)b[i] = 1ll * b[i+1] * (i+1) % mod;
for(int i = 0; i <= k; i ++)
{
tong = 1ll*pw(k-i, n) * C(i, n+1) % mod;
if(i&1)ans = (ans - tong + mod) % mod;
else ans = (ans + tong) % mod;
//cout << i <<" "<<tong<<'\n';
}
cout << ans;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
#define task "test"
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int test = 1;
//cin >> test;
while(test -- > 0)sol();
return 0;
}
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... |