Submission #2857758
Source Code Expand
#include <bits/stdc++.h> using namespace std; using lint = long long int; constexpr lint MOD = 1000000007; #define FOR(i, begin, end) for(int i=(begin);i<(end);i++) #define REP(i, n) FOR(i,0,n) lint power(lint x, lint n, lint MOD) { lint ans = 1; while (n>0) { if (n & 1) (ans *= x) %= MOD; (x *= x) %= MOD; n >>= 1; } return ans; } vector<lint> factorial; vector<lint> facInv; void factorialPre(int nmax) { factorial = facInv = vector<lint>(nmax + 1, 1); for (int i = 1; i <= nmax; i++) { factorial[i] = factorial[i-1] * i % MOD; } facInv[nmax] = power(factorial[nmax], MOD-2, MOD); for (int i = nmax - 1; i > 0; i--) { facInv[i] = facInv[i + 1] * (i + 1) % MOD; } } lint nCr(int n, int r) { if (n<r || r<0) return 0; return (factorial[n] * facInv[r] % MOD) * facInv[n-r] % MOD; } lint nPr(int n, int r) { if (n<r || r<0) return 0; return factorial[n] * facInv[n-r] % MOD; } int N, M; vector<int> A; int main() { cin >> N >> M; A.resize(M+1, 1); REP(i, M) cin >> A[i+1]; factorialPre(1 << N); vector<lint> dp(1 << N); dp[0] = 1; REP(m, M) { // 初手ゼータ変換 REP(i, N) REP(b, 1<<N) if (b & (1 << i)) (dp[b] += dp[b ^ (1 << i)]) %= MOD; // 場合の数をかける REP(b, 1<<N) dp[b] = (b + 1 >= A[m + 1] - 1) ? (dp[b] * nPr(b + 1 - A[m], A[m+1] - A[m]-1)) % MOD : 0; // メビウス変換で戻す REP(i, N) REP(b, 1<<N) if (b & (1 << i)) (dp[b] += MOD - dp[b ^ (1 << i)]) %= MOD; // A[m+1] を入れる REP(b, 1<<N) dp[b] = (b+1 >= A[m+1]) ? (dp[b] * (b+2-A[m+1]) % MOD) : 0; } lint ans = 0; for (auto v : dp) (ans += v) %= MOD; cout << (ans * factorial[(1 << N) - A.back()] % MOD) * (1 << N) % MOD << endl; }
Submission Info
Submission Time | |
---|---|
Task | F - Dark Horse |
User | hitonanode |
Language | C++14 (GCC 5.4.1) |
Score | 1100 |
Code Size | 1925 Byte |
Status | AC |
Exec Time | 62 ms |
Memory | 1792 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1100 / 1100 | ||||
Status |
|
|
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 | 6 ms | 384 KB |
02.txt | AC | 53 ms | 1792 KB |
03.txt | AC | 56 ms | 1792 KB |
04.txt | AC | 59 ms | 1792 KB |
05.txt | AC | 38 ms | 1792 KB |
06.txt | AC | 46 ms | 1792 KB |
07.txt | AC | 53 ms | 1792 KB |
08.txt | AC | 60 ms | 1792 KB |
09.txt | AC | 61 ms | 1792 KB |
10.txt | AC | 60 ms | 1792 KB |
11.txt | AC | 3 ms | 1792 KB |
12.txt | AC | 7 ms | 1792 KB |
13.txt | AC | 13 ms | 1792 KB |
14.txt | AC | 20 ms | 1792 KB |
15.txt | AC | 1 ms | 256 KB |
16.txt | AC | 1 ms | 256 KB |
17.txt | AC | 1 ms | 256 KB |
18.txt | AC | 1 ms | 256 KB |
19.txt | AC | 1 ms | 256 KB |
20.txt | AC | 1 ms | 256 KB |
21.txt | AC | 61 ms | 1792 KB |
22.txt | AC | 60 ms | 1792 KB |
23.txt | AC | 59 ms | 1792 KB |
24.txt | AC | 57 ms | 1792 KB |
25.txt | AC | 40 ms | 1792 KB |
26.txt | AC | 22 ms | 1792 KB |
27.txt | AC | 2 ms | 256 KB |
28.txt | AC | 1 ms | 256 KB |
29.txt | AC | 1 ms | 256 KB |
30.txt | AC | 1 ms | 256 KB |
31.txt | AC | 1 ms | 256 KB |
32.txt | AC | 62 ms | 1792 KB |
33.txt | AC | 1 ms | 256 KB |
34.txt | AC | 1 ms | 256 KB |
35.txt | AC | 1 ms | 256 KB |
36.txt | AC | 1 ms | 256 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |
sample-03.txt | AC | 1 ms | 256 KB |
sample-04.txt | AC | 1 ms | 256 KB |
sample-05.txt | AC | 62 ms | 1792 KB |