답안 #531970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531970 2022-03-02T02:05:43 Z Killer2501 Magneti (COCI21_magneti) C++14
60 / 110
106 ms 4780 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]);
                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 = 1; 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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 4684 KB Output is correct
2 Correct 24 ms 4540 KB Output is correct
3 Correct 9 ms 4684 KB Output is correct
4 Correct 5 ms 4684 KB Output is correct
5 Correct 16 ms 4664 KB Output is correct
6 Correct 39 ms 4708 KB Output is correct
7 Correct 44 ms 4684 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 28 ms 4660 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 4676 KB Output is correct
2 Correct 4 ms 4684 KB Output is correct
3 Correct 10 ms 4684 KB Output is correct
4 Correct 4 ms 4668 KB Output is correct
5 Correct 10 ms 4684 KB Output is correct
6 Correct 5 ms 4664 KB Output is correct
7 Correct 10 ms 4684 KB Output is correct
8 Correct 7 ms 4556 KB Output is correct
9 Correct 5 ms 4780 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 4556 KB Output is correct
2 Correct 11 ms 4648 KB Output is correct
3 Correct 16 ms 4652 KB Output is correct
4 Correct 12 ms 4656 KB Output is correct
5 Correct 15 ms 4652 KB Output is correct
6 Correct 10 ms 4556 KB Output is correct
7 Correct 15 ms 4648 KB Output is correct
8 Correct 7 ms 4536 KB Output is correct
9 Correct 11 ms 4556 KB Output is correct
10 Correct 7 ms 4556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 4684 KB Output is correct
2 Correct 24 ms 4540 KB Output is correct
3 Correct 9 ms 4684 KB Output is correct
4 Correct 5 ms 4684 KB Output is correct
5 Correct 16 ms 4664 KB Output is correct
6 Correct 39 ms 4708 KB Output is correct
7 Correct 44 ms 4684 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 28 ms 4660 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 9 ms 4676 KB Output is correct
12 Correct 4 ms 4684 KB Output is correct
13 Correct 10 ms 4684 KB Output is correct
14 Correct 4 ms 4668 KB Output is correct
15 Correct 10 ms 4684 KB Output is correct
16 Correct 5 ms 4664 KB Output is correct
17 Correct 10 ms 4684 KB Output is correct
18 Correct 7 ms 4556 KB Output is correct
19 Correct 5 ms 4780 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 15 ms 4556 KB Output is correct
22 Correct 11 ms 4648 KB Output is correct
23 Correct 16 ms 4652 KB Output is correct
24 Correct 12 ms 4656 KB Output is correct
25 Correct 15 ms 4652 KB Output is correct
26 Correct 10 ms 4556 KB Output is correct
27 Correct 15 ms 4648 KB Output is correct
28 Correct 7 ms 4536 KB Output is correct
29 Correct 11 ms 4556 KB Output is correct
30 Correct 7 ms 4556 KB Output is correct
31 Correct 98 ms 4704 KB Output is correct
32 Correct 73 ms 4684 KB Output is correct
33 Correct 100 ms 4704 KB Output is correct
34 Correct 31 ms 4684 KB Output is correct
35 Correct 98 ms 4708 KB Output is correct
36 Correct 12 ms 4704 KB Output is correct
37 Correct 100 ms 4684 KB Output is correct
38 Correct 46 ms 4644 KB Output is correct
39 Incorrect 96 ms 4684 KB Output isn't correct
40 Halted 0 ms 0 KB -