# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1059012 | 2024-08-14T16:00:12 Z | Thanhs | Magneti (COCI21_magneti) | C++14 | 136 ms | 237500 KB |
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long // #define double long double #define endl '\n' #define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define setmin(x, y) x = min((x), (y)) #define setmax(x, y) x = max((x), (y)) #define sqr(x) ((x) * (x)) #define fi first #define se second #define all(x) x.begin(), x.end() // mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count()); // int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);} const int NM = 50 + 5; const int LM = 1e4 + 5; const int mod = 1e9 + 7; struct mi { int v; mi() : v(0){} mi(int v) : v(v) { if (v >= mod) v -= mod; } mi operator+(const mi& o) { return mi(v + o.v); } mi operator-(const mi& o) { return mi(v + mod - o.v); } mi operator*(const mi& o) { return mi(1ll * v * o.v % mod); } mi& operator+=(const mi &o) { v += o.v; if (v >= mod) v -= mod; return *this; } mi& operator-=(const mi &o) { v += mod - o.v; if (v >= mod) v -= mod; return *this; } mi& operator*=(const mi& o) { v = 1ll * v * o.v % mod; return *this; } }fact[LM], invfact[LM], dp[NM][NM][LM], ans; mi C(int n, int k) { if (k < 0 || k > n) return mi(0); return fact[n] * invfact[k] * invfact[n - k]; } int n, l, a[NM]; mi bp(mi x, int y) { mi res(1); while (y) { if (y & 1) res = res * x; x = x * x; y >>= 1; } return res; } void pre() { fact[0].v = 1; for (int i = 1; i < LM; i++) fact[i] = fact[i - 1] * mi(i); invfact[LM - 1] = bp(fact[LM - 1], mod - 2); for (int i = LM - 1; i >= 1; i--) invfact[i - 1] = invfact[i] * mi(i); } void solve() { if (n > 10) return; pre(); cin >> n >> l; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i]--; } sort(a + 1, a + 1 + n); dp[0][0][0].v = 1; for (int i = 0; i < n; i++) for (int j = 0; j <= i; j++) for (int k = 0; k <= l; k++) if (dp[i][j][k].v) { dp[i + 1][j + 1][k] += dp[i][j][k]; if (k + a[i + 1] <= l) dp[i + 1][j][k + a[i + 1]] += mi(j) * mi(2) * dp[i][j][k]; if (j && k + 2 * a[i + 1] <= l) dp[i + 1][j - 1][k + 2 * a[i + 1]] += mi(j) * mi(j - 1) * dp[i][j][k]; } for (int i = 0; i <= l; i++) ans += dp[n][1][i] * C(l - i, n); cout << ans.v; } signed main() { fastIO if (fopen("in.txt", "r")) { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } int tc = 1; // cin >> tc; while (tc--) solve(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 101 ms | 237392 KB | Output is correct |
2 | Correct | 94 ms | 237392 KB | Output is correct |
3 | Correct | 94 ms | 237396 KB | Output is correct |
4 | Correct | 94 ms | 237396 KB | Output is correct |
5 | Correct | 94 ms | 237396 KB | Output is correct |
6 | Correct | 97 ms | 237352 KB | Output is correct |
7 | Correct | 100 ms | 237396 KB | Output is correct |
8 | Correct | 95 ms | 237396 KB | Output is correct |
9 | Correct | 98 ms | 237396 KB | Output is correct |
10 | Correct | 96 ms | 237396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 94 ms | 237480 KB | Output is correct |
2 | Correct | 107 ms | 237392 KB | Output is correct |
3 | Correct | 94 ms | 237472 KB | Output is correct |
4 | Correct | 94 ms | 237336 KB | Output is correct |
5 | Correct | 96 ms | 237400 KB | Output is correct |
6 | Correct | 94 ms | 237392 KB | Output is correct |
7 | Correct | 104 ms | 237320 KB | Output is correct |
8 | Correct | 100 ms | 237380 KB | Output is correct |
9 | Correct | 106 ms | 237392 KB | Output is correct |
10 | Correct | 106 ms | 237460 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 105 ms | 237324 KB | Output is correct |
2 | Correct | 104 ms | 237396 KB | Output is correct |
3 | Correct | 96 ms | 237416 KB | Output is correct |
4 | Correct | 95 ms | 237292 KB | Output is correct |
5 | Correct | 96 ms | 237268 KB | Output is correct |
6 | Correct | 109 ms | 237396 KB | Output is correct |
7 | Correct | 117 ms | 237376 KB | Output is correct |
8 | Correct | 96 ms | 237500 KB | Output is correct |
9 | Correct | 99 ms | 237460 KB | Output is correct |
10 | Correct | 98 ms | 237396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 101 ms | 237392 KB | Output is correct |
2 | Correct | 94 ms | 237392 KB | Output is correct |
3 | Correct | 94 ms | 237396 KB | Output is correct |
4 | Correct | 94 ms | 237396 KB | Output is correct |
5 | Correct | 94 ms | 237396 KB | Output is correct |
6 | Correct | 97 ms | 237352 KB | Output is correct |
7 | Correct | 100 ms | 237396 KB | Output is correct |
8 | Correct | 95 ms | 237396 KB | Output is correct |
9 | Correct | 98 ms | 237396 KB | Output is correct |
10 | Correct | 96 ms | 237396 KB | Output is correct |
11 | Correct | 94 ms | 237480 KB | Output is correct |
12 | Correct | 107 ms | 237392 KB | Output is correct |
13 | Correct | 94 ms | 237472 KB | Output is correct |
14 | Correct | 94 ms | 237336 KB | Output is correct |
15 | Correct | 96 ms | 237400 KB | Output is correct |
16 | Correct | 94 ms | 237392 KB | Output is correct |
17 | Correct | 104 ms | 237320 KB | Output is correct |
18 | Correct | 100 ms | 237380 KB | Output is correct |
19 | Correct | 106 ms | 237392 KB | Output is correct |
20 | Correct | 106 ms | 237460 KB | Output is correct |
21 | Correct | 105 ms | 237324 KB | Output is correct |
22 | Correct | 104 ms | 237396 KB | Output is correct |
23 | Correct | 96 ms | 237416 KB | Output is correct |
24 | Correct | 95 ms | 237292 KB | Output is correct |
25 | Correct | 96 ms | 237268 KB | Output is correct |
26 | Correct | 109 ms | 237396 KB | Output is correct |
27 | Correct | 117 ms | 237376 KB | Output is correct |
28 | Correct | 96 ms | 237500 KB | Output is correct |
29 | Correct | 99 ms | 237460 KB | Output is correct |
30 | Correct | 98 ms | 237396 KB | Output is correct |
31 | Correct | 136 ms | 237280 KB | Output is correct |
32 | Correct | 103 ms | 237420 KB | Output is correct |
33 | Correct | 107 ms | 237404 KB | Output is correct |
34 | Correct | 96 ms | 237396 KB | Output is correct |
35 | Correct | 109 ms | 237396 KB | Output is correct |
36 | Correct | 96 ms | 237396 KB | Output is correct |
37 | Correct | 107 ms | 237396 KB | Output is correct |
38 | Correct | 96 ms | 237320 KB | Output is correct |
39 | Correct | 105 ms | 237300 KB | Output is correct |
40 | Correct | 99 ms | 237264 KB | Output is correct |
41 | Correct | 105 ms | 237396 KB | Output is correct |
42 | Correct | 94 ms | 237396 KB | Output is correct |
43 | Correct | 101 ms | 237400 KB | Output is correct |
44 | Correct | 99 ms | 237252 KB | Output is correct |
45 | Correct | 108 ms | 237436 KB | Output is correct |
46 | Correct | 94 ms | 237396 KB | Output is correct |
47 | Correct | 100 ms | 237400 KB | Output is correct |
48 | Correct | 96 ms | 237396 KB | Output is correct |
49 | Correct | 93 ms | 237396 KB | Output is correct |
50 | Correct | 96 ms | 237292 KB | Output is correct |