Submission #232546

#TimeUsernameProblemLanguageResultExecution timeMemory
232546AlexLuchianovAsceticism (JOI18_asceticism)C++14
49 / 100
61 ms896 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; using ll = long long; #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) < (b)) ? (b) : (a)) int const nmax = 100000; int const modulo = 1000000007; int fact[1 + nmax]; void gcd(int a, int b, int &x, int &y){ if(b == 0){ x = 1; y = 0; } else { gcd(b, a % b, x, y); int aux = x; x = y; y = aux - a / b * y; } } void computefact(){ fact[0] = 1; for(int i = 1; i <= nmax; i++) fact[i] = 1LL * fact[i - 1] * i % modulo; } int invers(int number){ int x, y; gcd(number, modulo, x, y); x %= modulo; if(x < 0) x += modulo; return x; } int comb(int n, int k){ int result = fact[n]; int result2 = 1LL * fact[k] * fact[n - k] % modulo; return 1LL * result * invers(result2) % modulo; } int lgpow(int a, int b){ a = (modulo + a) % modulo; if(b == 0) return 1; else if(b == 1) return a; else { int result = lgpow(a, b / 2); if(b % 2 == 0) return 1LL * result * result % modulo; else return 1LL * result * result % modulo * a % modulo; } } int euler(int n, int m){ int result = 0; for(int i = 0; i <= m; i++){ result += (1LL * lgpow(-1, i) * comb(n + 1, i) % modulo) * lgpow(m + 1 - i, n) % modulo; if(modulo <= result) result -= modulo; } return result; } int main() { computefact(); int n, k; cin >> n >> k; cout << euler(n, n - k) << '\n'; 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...