Submission #838454

#TimeUsernameProblemLanguageResultExecution timeMemory
838454Charizard2021Magneti (COCI21_magneti)C++17
110 / 110
106 ms14924 KiB
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long fact[100002], inv[100002]; long long pw(long long b, long long e) { long long ans = 1; while(e) { if(e & 1) ans = (ans * b) % MOD; b = (b * b) % MOD; e >>= 1; } return ans; } long long C(long long n, long long k) { if(n < k){ return 0; } long long ans = fact[n]; ans *= inv[k]; ans %= MOD; ans *= inv[n-k]; ans %= MOD; return ans; } int main(){ fact[0] = 1; for(long long i = 1; i <= 100000; i++){ fact[i] = (fact[i-1] * i) % MOD; } inv[0] = 1; for(long long i = 1; i <= 100000; i++){ inv[i] = pw(fact[i], MOD-2); } long long n, l; cin >> n >> l; long long r[1 + n]; for(long long i = 1; i <= n; i++){ cin >> r[i]; } sort(r + 1, r + n + 1); bool allEqual = true; for(long long i = 1; i < n; i++){ if(r[i] != r[i + 1]){ allEqual = false; break; } } if(allEqual){ cout << (fact[n] * C(l - (n - 1) * r[1] - 1 + n, n)) % MOD << "\n"; } else{ vector<vector<vector<long long> > > dp(2, vector<vector<long long> >(5 + n, vector<long long>(5 + l, 0))); dp[0][0][0] = 1; long long cur = 0; for(long long i = 1; i <= n; i++){ cur ^= 1; dp[cur][0][0] = 0; long long rad = r[i]; for(long long j = 1; j <= i; j++){ for(long long k = 1; k <= l; k++){ dp[cur][j][k] = dp[!cur][j - 1][k - 1]; if(k >= rad){ dp[cur][j][k] = (dp[cur][j][k] + (dp[!cur][j][k - rad] * 2 * j) % MOD) % MOD; } if(k >= 2 * rad - 1){ dp[cur][j][k] = (dp[cur][j][k] + (dp[!cur][j + 1][k - 2 * rad + 1] * j * (j + 1)) % MOD) % MOD; } } } } long long ans = 0; for(long long i = 1; i <= l; i++){ ans = (ans + (dp[cur][1][i] * C(l - i + n, n)) % MOD) % MOD; } cout << ans << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...