Submission #2271354


Source Code Expand

/**
 * File    : F.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-3-28 09:59:45
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

const int MAX_SIZE = 1000010;
const long long MOD = 1000000007;

long long inv[MAX_SIZE];
long long fact[MAX_SIZE];
long long factinv[MAX_SIZE];

void init() {
  inv[1] = 1;
  for (int i=2; i<MAX_SIZE; i++) {
    inv[i] = ((MOD - inv[MOD%i]) * (MOD/i))%MOD;
  }
  fact[0] = factinv[0] = 1;
  for (int i=1; i<MAX_SIZE; i++) {
    fact[i] = (i * fact[i-1])%MOD;
    factinv[i] = (inv[i] * factinv[i-1])%MOD;
  }
}

long long C(int n, int k) {
  if (n >=0 && k >= 0 && n-k >= 0) {
    return ((fact[n] * factinv[k])%MOD * factinv[n-k])%MOD;
  }
  return 0;
}

long long power(long long x, long long n) {
  if (n == 0) {
    return 1;
  } else if (n%2 == 1) {
    return (x * power(x, n-1)) % MOD;
  } else {
    long long half = power(x, n/2);
    return (half * half) % MOD;
  }
}

long long gcm(long long a, long long b) {
  if (a < b) {
    return gcm(b, a);
  }
  if (b == 0) return a;
  return gcm(b, a%b);
}

int N, M;
ll A[100];
ll DP[(1 << 16)];
ll L[100];

int main()
{
  init();
  cin >> N >> M;
  for (auto i = 0; i < M; i++)
  {
    cin >> A[i];
    A[i]--;
  }
  fill(DP, DP + (1 << 16), 0);
  DP[0] = 1;
  for (auto k = M-1; k >= 0; k--)
  {
    for (auto i = (1 << N) - 1; i >= 0; i--)
    {
      if (DP[i] == 0)
        continue;
      for (auto j = 0; j < N; j++)
      {
        if (((i >> j) & 1) == 0)
        {
          DP[i + (1 << j)] += (C(power(2, N) - 1 - A[k] - i, power(2, j) - 1) * DP[i]) % MOD;
          DP[i + (1 << j)] %= MOD;
        }
      }
    }
  }
  for (auto i = 0; i < (1 << N); i++)
  {
    ll R = (1 << N) - 1 - i;
    for (auto j = 0; j < N; j++)
    {
      if (((i >> j) & 1) == 0)
      {
        DP[i] *= C(R, power(2, j));
        DP[i] %= MOD;
        R -= power(2, j);
      }
    }
    assert(R == 0);
  }
  ll X = 0;
  for (auto i = 0; i < (1 << N); i++)
  {
    int b = 0;
    for (auto j = 0; j < N; j++)
    {
      b += (i >> j) & 1;
    }
    if (b % 2 == 0)
    {
      X += DP[i];
    }
    else
    {
      X += MOD - DP[i];
    }
    X %= MOD;
  }
  for (auto i = 0; i < N; i++)
  {
    L[i] = 1;
    for (auto j = 0; j < i; j++)
    {
      L[i] *= (C(power(2, i) - power(2, j), power(2, j)) * L[j]) % MOD;
      L[i] %= MOD;
    }
  }
  for (auto i = 0; i < N; i++)
  {
    X *= L[i];
    X %= MOD;
  }
  X *= power(2, power(2, N) - 1);
  X %= MOD;
  cout << X << endl;
}

Submission Info

Submission Time
Task F - Dark Horse
User kazunetakahashi
Language C++14 (GCC 5.4.1)
Score 1100
Code Size 3354 Byte
Status AC
Exec Time 321 ms
Memory 24192 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1100 / 1100
Status
AC × 5
AC × 41
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, sample-05.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, sample-05.txt
Case Name Status Exec Time Memory
01.txt AC 58 ms 24192 KB
02.txt AC 229 ms 24192 KB
03.txt AC 238 ms 24192 KB
04.txt AC 229 ms 24192 KB
05.txt AC 127 ms 24192 KB
06.txt AC 184 ms 24192 KB
07.txt AC 215 ms 24192 KB
08.txt AC 262 ms 24192 KB
09.txt AC 282 ms 24192 KB
10.txt AC 253 ms 24192 KB
11.txt AC 55 ms 24192 KB
12.txt AC 55 ms 24192 KB
13.txt AC 55 ms 24192 KB
14.txt AC 57 ms 24192 KB
15.txt AC 35 ms 24192 KB
16.txt AC 36 ms 24192 KB
17.txt AC 35 ms 24192 KB
18.txt AC 35 ms 24192 KB
19.txt AC 36 ms 24192 KB
20.txt AC 36 ms 24192 KB
21.txt AC 299 ms 24192 KB
22.txt AC 276 ms 24192 KB
23.txt AC 189 ms 24192 KB
24.txt AC 72 ms 24192 KB
25.txt AC 135 ms 24192 KB
26.txt AC 58 ms 24192 KB
27.txt AC 36 ms 24192 KB
28.txt AC 36 ms 24192 KB
29.txt AC 36 ms 24192 KB
30.txt AC 36 ms 24192 KB
31.txt AC 36 ms 24192 KB
32.txt AC 321 ms 24192 KB
33.txt AC 35 ms 24192 KB
34.txt AC 36 ms 24192 KB
35.txt AC 36 ms 24192 KB
36.txt AC 35 ms 24192 KB
sample-01.txt AC 36 ms 24192 KB
sample-02.txt AC 35 ms 24192 KB
sample-03.txt AC 36 ms 24192 KB
sample-04.txt AC 35 ms 24192 KB
sample-05.txt AC 304 ms 24192 KB