Submission #957616

# Submission time Handle Problem Language Result Execution time Memory
957616 2024-04-04T05:51:27 Z vjudge1 Zapina (COCI20_zapina) C++17
55 / 110
52 ms 500 KB
#include <bits/stdc++.h>
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);
#define what(x) cerr << #x << " is " << x << '\n';
#define kill(x) {cout << x << '\n'; return;}
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define pb push_back
#define ll long long
#define F first
#define S second
const ll inf = 1e16, mod = 1e9 + 7, delta = 1e9 + 9, SQ = 350, P = 6065621;

using namespace std;

const int N = 60, LG = 21;
ll fac[N], inv[N], pw[N][N];

ll poww (ll a, ll b) {
  if (!b) return 1;
  if (b & 1) return a * poww(a * a % mod, b / 2) % mod;
  return poww(a * a % mod, b / 2);
}

ll C(int n, int r) {
  if (r > n || r < 0) return 0;
  if (r == n || r == 0) return 1;
  return fac[n] * inv[r] % mod * inv[n - r] % mod;
}

int main () {
  fast_io;
  fac[0] = 1;
  for (int i = 1; i < N; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = poww(fac[i], mod - 2);
  }
  for (int i = 1; i < N; i++) {
    pw[i][0] = 1;
    for (int j = 1; j < N; j++) {
      pw[i][j] = pw[i][j - 1] * i % mod;
    }
  }
  int n;
  cin >> n;
  ll ans = 0;
  for (int mask = 1; mask < (1 << n); mask++) {
    int tmp = 0;
    for (int i = 0; i < n; i++)
      if (mask & (1 << i))
        tmp += i + 1;
    if (tmp > n) continue;
    int cur = n;
    ll res = 1;
    for (int i = 0; i < n; i++) {
      if (mask & (1 << i)) {
        res = res * C(cur, i + 1) % mod;
        cur -= (i + 1);
      }
    }
    int b = __builtin_popcount(mask);
    if (cur > 0) {
      res = res * pw[n - b][cur] % mod;
    }
    if (b & 1) {
      ans = (ans + res) % mod;
    }
    else {
      ans -= res;
      ans += mod;
      ans %= mod;
    }
  }
  cout << ans << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 356 KB Output is correct
7 Correct 1 ms 484 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 484 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 480 KB Output is correct
14 Correct 4 ms 344 KB Output is correct
15 Correct 8 ms 348 KB Output is correct
16 Correct 15 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 356 KB Output is correct
7 Correct 1 ms 484 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 484 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 480 KB Output is correct
14 Correct 4 ms 344 KB Output is correct
15 Correct 8 ms 348 KB Output is correct
16 Correct 15 ms 344 KB Output is correct
17 Incorrect 52 ms 476 KB Output isn't correct
18 Halted 0 ms 0 KB -