Submission #154281

#TimeUsernameProblemLanguageResultExecution timeMemory
154281karmaAsceticism (JOI18_asceticism)C++14
100 / 100
15 ms2040 KiB
#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)

asceticism.cpp: In function 'int main()':
asceticism.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
asceticism.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...