Submission #19944

#TimeUsernameProblemLanguageResultExecution timeMemory
19944tonyjjw순열 (kriii4_T)C++14
8 / 100
472 ms40784 KiB
#include <algorithm> #include <assert.h> #include <complex> #include <ctype.h> #include <functional> #include <iostream> #include <limits.h> #include <locale.h> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <vector> #include <unordered_set> #include <unordered_map> #pragma warning(disable:4996) using namespace std; #define mp make_pair typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair <int, int> pii; typedef pair <ll, ll> pll; typedef pair <ll, int> pli; typedef pair <ldb, ldb> pdd; int IT_MAX = 131072; const ll MOD = 1000000007; const int INF = 1034567891; const ll LL_INF = 2234567890123456789ll; const db PI = 3.141592653589793238; const ldb ERR = 1E-10; ll mul_inv(ll a, ll b) { ll b0 = b, t, q; ll x0 = 0, x1 = 1; if (b == 1) return 1; while (a > 1) { q = a / b; t = b, b = a % b, a = t; t = x0, x0 = x1 - q * x0, x1 = t; } if (x1 < 0) x1 += b0; return x1; } ll F[1000050]; ll Finv[1000050]; ll dp1[1000050]; ll dp2[1000050]; ll dp3[1000050]; inline ll Comb(int x, int y) { ll rv = F[x]; rv = (rv * Finv[y]) % MOD; rv = (rv * Finv[x - y]) % MOD; return rv; } int main() { int N, L, K, i; F[0] = 1; for (i = 1; i <= 1000010; i++) F[i] = (F[i - 1] * i) % MOD; for (i = 0; i <= 1000010; i++) Finv[i] = mul_inv(F[i], MOD); scanf("%d %d", &N, &K); K++; if (K == N + 1) return !printf("0\n"); ll ans = Comb(N - K + 2, 2) * N % MOD; ans -= 2 * Comb(N - K + 2, 3); ans = (ans + 2 * MOD) % MOD; ans = (ans*N) % MOD; ans = (ans*F[N - 1]) % MOD; for (L = K; L < N; L++) { dp1[L] = Comb(N + 1, L + 1) * L % MOD; dp2[L] = Comb(N + 2, L + 2); dp2[L] = dp2[L] * L % MOD * (L + 1) % MOD; dp2[L] = (dp2[L] - dp1[L] + MOD) % MOD; dp3[L] = Comb(N + 3, L + 3) * L % MOD; dp3[L] = dp3[L] * (L + 1) % MOD * (L + 2) % MOD; dp3[L] = (dp3[L] - 3 * dp2[L] + 3 * MOD) % MOD; dp3[L] = (dp3[L] - 2 * dp1[L] + 2 * MOD) % MOD; ll t = Comb(L - K + 2, 2)*L%MOD; t -= 2 * Comb(L - K + 2, 3); t = (t + 2 * MOD) % MOD; t = (t * F[N - L - 1]) % MOD; t = (t * F[L-1]) % MOD; ll t2 = 0; t2 += (2 * N * dp1[L]) % MOD; t2 -= 2 * dp2[L]; t2 += N*(N - 1) % MOD*dp1[L] % MOD; t2 -= (2 * N - 1) * dp2[L] % MOD; t2 += dp3[L]; t2 = (t2 + 100 * MOD) % MOD; ans += (t*t2) % MOD; } ans = ans % MOD; ll sum = 0; for (i = 1; i + K - 1 <= N; i++) sum += (N - i - K + 2); sum %= MOD; sum *= N + 1; sum %= MOD; sum = (sum * F[N]) % MOD; ans = sum - ans; ans %= MOD; ans += MOD; ans %= MOD; printf("%lld\n", ans); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...