Submission #658876

#TimeUsernameProblemLanguageResultExecution timeMemory
658876FoxyyMagneti (COCI21_magneti)C++17
0 / 110
1081 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define Foxyy cin.tie(0); cout.sync_with_stdio(0); cout.tie(0); const int MOD = 1e9+7; struct Solver { int& n; int& l; vector<int>& r; vector<int> fac{}; void getFac() { fac.resize(l+1); fac[0] = 1; for (int i = 1; i <= l; i++) { fac[i] = 1LL * fac[i-1] * i % MOD; } } ll fastPow(int base, int power) { if (power == 0) return 1; if (power % 2) return fastPow(base, power-1) * base % MOD; ll ret = fastPow(base, power/2); return ret*ret % MOD; } void solve() { if (n == 1) { cout << l << '\n'; return; } getFac(); int ans = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (i != j) { int sum = r[i] + r[j]; for (int k = 0; k < n; k++) if (k != i and k != j) { sum += 2*r[k] - 1; } int spaces = l - sum; if (spaces < 0) { continue; } for (int midSpaces = 0; midSpaces <= spaces; midSpaces++) { int removed = spaces - midSpaces; ans = (ans + 1LL * (removed+1) * fac[n-2 + midSpaces] % MOD * fastPow(fac[midSpaces], MOD-2) % MOD) % MOD; } } cout << ans << '\n'; } }; signed main() { Foxyy int T = 1; // cin >> T; while(T--) { int n, l; cin >> n >> l; vector<int> r(n); for (auto& x : r) { cin >> x; } Solver solver{n, l, r}; solver.solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...