제출 #342368

#제출 시각아이디문제언어결과실행 시간메모리
342368jovan_bAsceticism (JOI18_asceticism)C++17
100 / 100
80 ms2028 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pb push_back const int MOD = 1000000007; int add(int a, int b){ a += b; if(a >= MOD) a -= MOD; return a; } int mul(int a, int b){ return (1LL*a*b)%MOD; } int pw(int a, int b){ if(b == 0) return 1; int res = pw(a, b/2); res = mul(res, res); if(b%2) res = mul(res, a); return res; } int fak[200005]; int inv[200005]; int bin(int n, int k){ if(n < 0 || k < 0 || n < k) return 0; int res = fak[n]; res = mul(res, inv[k]); res = mul(res, inv[n-k]); return res; } int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; int n, m; cin >> n >> m; m = n-m; int res = 0; fak[0] = inv[0] = 1; for(int i=1; i<=200000; i++){ fak[i] = mul(fak[i-1], i); inv[i] = pw(fak[i], MOD-2); } for(int k=0; k<=m+1; k++){ int tr = pw(m+1-k, n); tr = mul(tr, bin(n+1, k)); if(k%2) res = add(res, MOD-tr); else res = add(res, tr); } cout << res << "\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...