Submission #5033613
Source Code Expand
#include "bits/stdc++.h" using namespace std; typedef long long ll; const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; ll mod_pow(ll a, ll n) { if (n == 0) return 1; if (n % 2 == 0) { ll tmp = mod_pow(a, n / 2); return (tmp * tmp) % MOD; } return (a * mod_pow(a, n - 1)) % MOD; } vector<ll> fact; vector<ll> inv_fact; void comb_init(int n) { fact.resize(n + 1); inv_fact.resize(n + 1); fact[0] = inv_fact[0] = 1; for (int i = 1; i <= n; i++) { fact[i] = (fact[i - 1] * i) % MOD; inv_fact[i] = (inv_fact[i - 1] * mod_pow(i, MOD - 2)) % MOD; } } ll dp1[17][1 << 16]; ll dp3[17][1 << 16]; int A[17]; int main() { int N, M; cin >> N >> M; comb_init(1 << N); A[0] = 1; for (int i = 1; i <= M; i++) cin >> A[i]; dp1[0][0] = 1; for (int i = 1; i <= M; i++) { for (int j = 0; j < N; j++) for (int b = 0; b < (1 << N); b++) if (b&(1 << j)) (dp1[i - 1][b] += dp1[i - 1][b ^ (1 << j)]) %= MOD; for (int U = 0; U < (1 << N); U++) { int t = U - (A[i - 1] - 1); int d = A[i] - 1 - A[i - 1]; if (t >= d) { dp3[i][U] = (fact[t] * inv_fact[t - d]) % MOD; (dp3[i][U] *= dp1[i - 1][U]) %= MOD; } } for (int j = 0; j < N; j++) for (int b = 0; b < (1 << N); b++) if (b&(1 << j)) (dp3[i][b] += MOD - dp3[i][b ^ (1 << j)]) %= MOD; for (int U = 0; U < (1 << N); U++) if (U >= A[i] - 2) dp1[i][U] = dp3[i][U] * (U - (A[i] - 2)) % MOD; } ll ret = 0; for (int U = 0; U < (1 << N); U++) (ret += dp1[M][U]) %= MOD; (ret *= fact[(1 << N) - A[M]]) %= MOD; (ret *= 1 << N) %= MOD; cout << ret << endl; }
Submission Info
Submission Time | |
---|---|
Task | F - Dark Horse |
User | Div9851 |
Language | C++14 (GCC 5.4.1) |
Score | 1100 |
Code Size | 1586 Byte |
Status | AC |
Exec Time | 83 ms |
Memory | 18048 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 | 11 ms | 14976 KB |
02.txt | AC | 74 ms | 17152 KB |
03.txt | AC | 77 ms | 17152 KB |
04.txt | AC | 80 ms | 17664 KB |
05.txt | AC | 59 ms | 15104 KB |
06.txt | AC | 67 ms | 17152 KB |
07.txt | AC | 73 ms | 17152 KB |
08.txt | AC | 81 ms | 17664 KB |
09.txt | AC | 82 ms | 17664 KB |
10.txt | AC | 81 ms | 17792 KB |
11.txt | AC | 20 ms | 3328 KB |
12.txt | AC | 24 ms | 3840 KB |
13.txt | AC | 33 ms | 8960 KB |
14.txt | AC | 39 ms | 8960 KB |
15.txt | AC | 2 ms | 4352 KB |
16.txt | AC | 2 ms | 6400 KB |
17.txt | AC | 3 ms | 8448 KB |
18.txt | AC | 3 ms | 10496 KB |
19.txt | AC | 3 ms | 8448 KB |
20.txt | AC | 4 ms | 14592 KB |
21.txt | AC | 82 ms | 17920 KB |
22.txt | AC | 81 ms | 17664 KB |
23.txt | AC | 80 ms | 17792 KB |
24.txt | AC | 78 ms | 17664 KB |
25.txt | AC | 59 ms | 15104 KB |
26.txt | AC | 40 ms | 8960 KB |
27.txt | AC | 4 ms | 10496 KB |
28.txt | AC | 2 ms | 4352 KB |
29.txt | AC | 3 ms | 10496 KB |
30.txt | AC | 2 ms | 6400 KB |
31.txt | AC | 4 ms | 14592 KB |
32.txt | AC | 83 ms | 18048 KB |
33.txt | AC | 1 ms | 2304 KB |
34.txt | AC | 2 ms | 6400 KB |
35.txt | AC | 4 ms | 12544 KB |
36.txt | AC | 4 ms | 14592 KB |
sample-01.txt | AC | 2 ms | 2304 KB |
sample-02.txt | AC | 2 ms | 4352 KB |
sample-03.txt | AC | 2 ms | 2304 KB |
sample-04.txt | AC | 2 ms | 4352 KB |
sample-05.txt | AC | 82 ms | 18048 KB |