Submission #903425

# Submission time Handle Problem Language Result Execution time Memory
903425 2024-01-11T07:39:34 Z duckindog Magneti (COCI21_magneti) C++14
110 / 110
242 ms 52888 KB
//from duckindog wth depression
#include<bits/stdc++.h>

using namespace std;

const int N = 50 + 10,
          L = 1e4 + 10,
          M = 1e9 + 7;
int n, l;
int a[N];
int f[N][N][L];

const int F = 1e5 + 10;
int fac[F], ifac[F];
int powder(int a, int b) {
  int ret = 1;
  while (b) {
    if (b & 1) ret = 1ll * ret * a % M;
    a = 1ll * a * a % M;
    b /= 2;
  }
  return ret;
}
int C(int n, int k) {
  if (n < k) return 0;
  return 1ll * fac[n] * ifac[k] % M * ifac[n - k] % M;
}
void init() {

  int x = 1e5;
  fac[1] = 1;
  for (int i = 2; i <= x; ++i) fac[i] = 1ll * fac[i - 1] * i % M;
  ifac[x] = powder(fac[x], M - 2);
  for (int i = x; i >= 1; --i) ifac[i - 1] = 1ll * ifac[i] * i % M;

}

void add(int &x, long long y) {
  x = ((x + y) % M + M) % M;
}

int32_t main() {
  cin.tie(0)->sync_with_stdio(0);

  if (fopen("duck.inp", "r")) {
    freopen("duck.inp", "r", stdin);
    freopen("duck.out", "w", stdout);
  }
  init();

  cin >> n >> l;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  sort(a + 1, a + n + 1);

  f[0][0][0] = 1;

  int x = 4, y = 2, z = 4;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= i; ++j) {
      for (int t = 1; t <= l; ++t) {
        auto &ret = f[i][j][t];
        int r = a[i];

        //create
        add(ret, 1ll * f[i - 1][j - 1][t - 1]);

        //add
        if (r <= t) add(ret, 1ll * f[i - 1][j][t - r] * 2 * j % M);

        //connect
        if (2 * r - 1 <= t)
          add(ret, 1ll * f[i - 1][j + 1][t - 2 * r + 1] * j * (j + 1) % M);

      }
    }
  }

  int answer = 0;
  for (int i = 1; i <= l; ++i) add(answer, 1ll * f[n][1][i] * C(n + l - i, n) % M);
  cout << answer << '\n';

}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:57:7: warning: unused variable 'x' [-Wunused-variable]
   57 |   int x = 4, y = 2, z = 4;
      |       ^
Main.cpp:57:14: warning: unused variable 'y' [-Wunused-variable]
   57 |   int x = 4, y = 2, z = 4;
      |              ^
Main.cpp:57:21: warning: unused variable 'z' [-Wunused-variable]
   57 |   int x = 4, y = 2, z = 4;
      |                     ^
Main.cpp:46:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     freopen("duck.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     freopen("duck.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 216 ms 52772 KB Output is correct
2 Correct 6 ms 8196 KB Output is correct
3 Correct 13 ms 4956 KB Output is correct
4 Correct 4 ms 2908 KB Output is correct
5 Correct 16 ms 6236 KB Output is correct
6 Correct 56 ms 18448 KB Output is correct
7 Correct 51 ms 32136 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 22 ms 17236 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4672 KB Output is correct
2 Correct 3 ms 2664 KB Output is correct
3 Correct 9 ms 4712 KB Output is correct
4 Correct 3 ms 2920 KB Output is correct
5 Correct 9 ms 4860 KB Output is correct
6 Correct 3 ms 2920 KB Output is correct
7 Correct 9 ms 4728 KB Output is correct
8 Correct 3 ms 2920 KB Output is correct
9 Correct 2 ms 2960 KB Output is correct
10 Correct 2 ms 2664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5212 KB Output is correct
2 Correct 3 ms 3676 KB Output is correct
3 Correct 5 ms 5232 KB Output is correct
4 Correct 3 ms 3940 KB Output is correct
5 Correct 5 ms 5212 KB Output is correct
6 Correct 3 ms 3420 KB Output is correct
7 Correct 5 ms 3540 KB Output is correct
8 Correct 2 ms 1372 KB Output is correct
9 Correct 3 ms 3676 KB Output is correct
10 Correct 2 ms 1380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 216 ms 52772 KB Output is correct
2 Correct 6 ms 8196 KB Output is correct
3 Correct 13 ms 4956 KB Output is correct
4 Correct 4 ms 2908 KB Output is correct
5 Correct 16 ms 6236 KB Output is correct
6 Correct 56 ms 18448 KB Output is correct
7 Correct 51 ms 32136 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 22 ms 17236 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 13 ms 4672 KB Output is correct
12 Correct 3 ms 2664 KB Output is correct
13 Correct 9 ms 4712 KB Output is correct
14 Correct 3 ms 2920 KB Output is correct
15 Correct 9 ms 4860 KB Output is correct
16 Correct 3 ms 2920 KB Output is correct
17 Correct 9 ms 4728 KB Output is correct
18 Correct 3 ms 2920 KB Output is correct
19 Correct 2 ms 2960 KB Output is correct
20 Correct 2 ms 2664 KB Output is correct
21 Correct 6 ms 5212 KB Output is correct
22 Correct 3 ms 3676 KB Output is correct
23 Correct 5 ms 5232 KB Output is correct
24 Correct 3 ms 3940 KB Output is correct
25 Correct 5 ms 5212 KB Output is correct
26 Correct 3 ms 3420 KB Output is correct
27 Correct 5 ms 3540 KB Output is correct
28 Correct 2 ms 1372 KB Output is correct
29 Correct 3 ms 3676 KB Output is correct
30 Correct 2 ms 1380 KB Output is correct
31 Correct 194 ms 52888 KB Output is correct
32 Correct 145 ms 37468 KB Output is correct
33 Correct 242 ms 52708 KB Output is correct
34 Correct 51 ms 14160 KB Output is correct
35 Correct 197 ms 52752 KB Output is correct
36 Correct 13 ms 5812 KB Output is correct
37 Correct 192 ms 52732 KB Output is correct
38 Correct 40 ms 15444 KB Output is correct
39 Correct 201 ms 52844 KB Output is correct
40 Correct 81 ms 18516 KB Output is correct
41 Correct 206 ms 52752 KB Output is correct
42 Correct 3 ms 3160 KB Output is correct
43 Correct 205 ms 52700 KB Output is correct
44 Correct 19 ms 8276 KB Output is correct
45 Correct 182 ms 52744 KB Output is correct
46 Correct 2 ms 2648 KB Output is correct
47 Correct 36 ms 19208 KB Output is correct
48 Correct 15 ms 12160 KB Output is correct
49 Correct 3 ms 3676 KB Output is correct
50 Correct 2 ms 2908 KB Output is correct