Submission #903329

# Submission time Handle Problem Language Result Execution time Memory
903329 2024-01-11T07:07:18 Z duckindog Magneti (COCI21_magneti) C++14
0 / 110
187 ms 102964 KB
//from duckindog wth depression
#include<bits/stdc++.h>

using namespace std;

#define int long long

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, int y) {
  x = ((1ll * 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;
  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, 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] * C(2, j) % M);

      }
    }
  }

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

}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     freopen("duck.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:49:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     freopen("duck.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 187 ms 102964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 7004 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 5720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 187 ms 102964 KB Output isn't correct
2 Halted 0 ms 0 KB -