Submission #531974

# Submission time Handle Problem Language Result Execution time Memory
531974 2022-03-02T02:10:27 Z Killer2501 Magneti (COCI21_magneti) C++14
110 / 110
115 ms 4808 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<ll, int>
#define fi first
#define se second
using namespace std;
const int N = 1e4+2;
const int M = 52;
const int mod = 1e9+7;
const ll base = 75;
const ll inf = 1e16;
int n, lab[N], t, c[N+M], h[N], P[N][20], m, a[N], b[N+M], ans, d[N], k, lst[M][N], dp[M][N];
vector<int> adj[N];
vector<int> vi;
string s;
bool vis[N];
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n&1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}
void add(int& x, int y)
{
    x += y;
    if(x >= mod)x -= mod;
}
int findp(int u)
{
    return lab[u] < 0 ? u : lab[u] = findp(lab[u]);
}
void hop(int u, int v)
{
    u = findp(u);
    v = findp(v);
    if(u == v)return;
    if(lab[u] > lab[v])swap(u, v);
    lab[u] += lab[v];
    lab[v] = u;
}
int C(int u, int v)
{
    if(u > v)return 0;
    return 1ll * b[v] * c[u] % mod * c[v-u] % mod;
}
void sol()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)cin >> a[i];
    b[0] = c[0] = 1;
    for(int i = 1; i <= m+n; i ++)b[i] = 1ll * b[i-1] * i % mod;
    c[m+n] = pw(b[m+n], mod-2);
    for(int i = m+n-1; i > 0; i --)c[i] = 1ll * c[i+1] * (i+1) % mod;
    sort(a+1, a+1+n);
    lst[1][1] = 1;
    for(int i = 2; i <= n; i ++)
    {
        memset(dp, 0, sizeof(dp));
        for(int j = 1; j < i; j ++)
        {
            for(int l = i-1; l <= m; l ++)
            {
                add(dp[j+1][l+1], lst[j][l]);
                if(l+a[i] <= m)add(dp[j][l+a[i]], 2ll * j * lst[j][l] % mod);
                if(j > 1 && l+a[i]*2-1 <= m)add(dp[j-1][l+a[i]*2-1], 1ll * j * (j-1) * lst[j][l] % mod);
            }
        }
        swap(dp, lst);
    }
    for(int i = n; i <= m; i ++)add(ans, 1ll * lst[1][i] * C(n, m-i+n) % mod);
    cout << ans;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    #define task "test"
    if(fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int test = 1;
    //cin >> test;
    while(test -- > 0)sol();
    return 0;
}
/*
1234
21
*/

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 104 ms 4700 KB Output is correct
2 Correct 24 ms 4556 KB Output is correct
3 Correct 11 ms 4684 KB Output is correct
4 Correct 4 ms 4684 KB Output is correct
5 Correct 15 ms 4556 KB Output is correct
6 Correct 36 ms 4684 KB Output is correct
7 Correct 38 ms 4556 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 27 ms 4664 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 4684 KB Output is correct
2 Correct 3 ms 4688 KB Output is correct
3 Correct 9 ms 4716 KB Output is correct
4 Correct 4 ms 4684 KB Output is correct
5 Correct 9 ms 4684 KB Output is correct
6 Correct 5 ms 4684 KB Output is correct
7 Correct 10 ms 4708 KB Output is correct
8 Correct 7 ms 4648 KB Output is correct
9 Correct 4 ms 4684 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 4644 KB Output is correct
2 Correct 10 ms 4556 KB Output is correct
3 Correct 15 ms 4648 KB Output is correct
4 Correct 11 ms 4556 KB Output is correct
5 Correct 16 ms 4684 KB Output is correct
6 Correct 11 ms 4556 KB Output is correct
7 Correct 15 ms 4556 KB Output is correct
8 Correct 6 ms 4556 KB Output is correct
9 Correct 10 ms 4576 KB Output is correct
10 Correct 6 ms 4640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 4700 KB Output is correct
2 Correct 24 ms 4556 KB Output is correct
3 Correct 11 ms 4684 KB Output is correct
4 Correct 4 ms 4684 KB Output is correct
5 Correct 15 ms 4556 KB Output is correct
6 Correct 36 ms 4684 KB Output is correct
7 Correct 38 ms 4556 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 27 ms 4664 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 9 ms 4684 KB Output is correct
12 Correct 3 ms 4688 KB Output is correct
13 Correct 9 ms 4716 KB Output is correct
14 Correct 4 ms 4684 KB Output is correct
15 Correct 9 ms 4684 KB Output is correct
16 Correct 5 ms 4684 KB Output is correct
17 Correct 10 ms 4708 KB Output is correct
18 Correct 7 ms 4648 KB Output is correct
19 Correct 4 ms 4684 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 16 ms 4644 KB Output is correct
22 Correct 10 ms 4556 KB Output is correct
23 Correct 15 ms 4648 KB Output is correct
24 Correct 11 ms 4556 KB Output is correct
25 Correct 16 ms 4684 KB Output is correct
26 Correct 11 ms 4556 KB Output is correct
27 Correct 15 ms 4556 KB Output is correct
28 Correct 6 ms 4556 KB Output is correct
29 Correct 10 ms 4576 KB Output is correct
30 Correct 6 ms 4640 KB Output is correct
31 Correct 108 ms 4684 KB Output is correct
32 Correct 70 ms 4684 KB Output is correct
33 Correct 103 ms 4684 KB Output is correct
34 Correct 28 ms 4684 KB Output is correct
35 Correct 108 ms 4808 KB Output is correct
36 Correct 12 ms 4684 KB Output is correct
37 Correct 102 ms 4692 KB Output is correct
38 Correct 33 ms 4556 KB Output is correct
39 Correct 98 ms 4684 KB Output is correct
40 Correct 35 ms 4668 KB Output is correct
41 Correct 100 ms 4684 KB Output is correct
42 Correct 6 ms 4672 KB Output is correct
43 Correct 115 ms 4664 KB Output is correct
44 Correct 16 ms 4684 KB Output is correct
45 Correct 100 ms 4684 KB Output is correct
46 Correct 3 ms 4684 KB Output is correct
47 Correct 23 ms 4664 KB Output is correct
48 Correct 21 ms 4660 KB Output is correct
49 Correct 6 ms 4684 KB Output is correct
50 Correct 6 ms 4556 KB Output is correct