Submission #850328

#TimeUsernameProblemLanguageResultExecution timeMemory
850328serifefedartarMagneti (COCI21_magneti)C++17
10 / 110
151 ms125448 KiB
#include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0); #define s second #define f first typedef long long ll; const ll MOD = 1e9 + 7; const ll LOGN = 20; const ll MAXN = 12000; ll expo(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b /= 2; } return res; } ll fact[MAXN], inv[MAXN]; ll dp[55][55][MAXN]; ll nCr(ll n, ll r) { if (r > n) return 0LL; if (r == n || r == 1 || r == 0) return 1LL; return ((fact[n] * inv[r]) % MOD * inv[n-r]) % MOD; } ll dist(ll item, ll plc) { return nCr(item + plc - 1, item); } vector<ll> seq; int main() { fast fact[0] = inv[0] = 1; for (ll i = 1; i < MAXN; i++) { fact[i] = (fact[i-1] * i) % MOD; inv[i] = expo(fact[i], MOD-2); } ll N, L; cin >> N >> L; seq = vector<ll>(N); for (int i = 0; i < N; i++) cin >> seq[i]; sort(seq.begin(), seq.end()); dp[0][0][0] = 1; for (int i = 1; i <= N; i++) { for (int open = 0; open <= i; open++) { if (i != 1 && open == 0) continue; for (int len = 0; len < MAXN; len++) { dp[i][open+1][len + 1] = (dp[i][open+1][len + 1] + dp[i-1][open][len]) % MOD; if (open != 0) dp[i][open][len + seq[i-1]] = (dp[i][open][len + seq[i-1]] + 2 * open * dp[i-1][open][len]) % MOD; if (open > 1) dp[i][open-1][len + 2 * seq[i-1] - 1] = (dp[i][open-1][len + 2 * seq[i-1] - 1] + open * (open-1) * dp[i-1][open][len]) % MOD; } } } ll ans = 0; for (int d = 1; d <= L; d++) { ll ways = dp[N][1][d]; ll open = L - d; ans = (ans + ways * dist(open, N+1)) % MOD; } cout << ans << "\n"; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:61:64: warning: iteration 11999 invokes undefined behavior [-Waggressive-loop-optimizations]
   61 |                 dp[i][open+1][len + 1] = (dp[i][open+1][len + 1] + dp[i-1][open][len]) % MOD;
      |                                           ~~~~~~~~~~~~~~~~~~~~~^
Main.cpp:60:35: note: within this loop
   60 |             for (int len = 0; len < MAXN; len++) {
      |                               ~~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...