結果
問題 | No.767 配られたジャパリまん |
ユーザー |
|
提出日時 | 2024-10-15 22:47:08 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 256 ms / 2,000 ms |
コード長 | 1,607 bytes |
コンパイル時間 | 2,206 ms |
コンパイル使用メモリ | 205,044 KB |
実行使用メモリ | 13,440 KB |
最終ジャッジ日時 | 2024-10-15 22:51:34 |
合計ジャッジ時間 | 4,481 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 15 |
ソースコード
#include <bits/stdc++.h>using LL = long long;const int N = 20;const int M = 2e5 + 7;const int S = 1 << N;const int MOD = 1e8 + 7;struct dat {int x, y, id;bool operator < (const dat &o) const {return x != o.x ? x < o.x : y < o.y;}};dat a[N];int f[S], g[S], n, h, w, fac[M], ivf[M];int pow(int x, int y) {int ret = 1;while(y) {if(y & 1)ret = 1LL * ret * x % MOD;x = 1LL * x * x % MOD;y >>= 1;}return ret;}int get(int x, int y) {return x < 0 || y < 0 ? 0 : 1LL * fac[x + y] * ivf[x] % MOD * ivf[y] % MOD;}int main() {fac[0] = 1, ivf[0] = 1;for(int i = 1; i < M; ++i) {fac[i] = 1LL * fac[i - 1] * i % MOD;ivf[i] = pow(fac[i], MOD - 2);}scanf("%d%d%d", &h, &w, &n);for(int i = 0; i < n; ++i) {scanf("%d%d", &a[i].x, &a[i].y);a[i].id = i;}std::sort(a, a + n);f[0] = 1;for(int i = 0; i < (1 << n); ++i) {int x = 0, y = 0, p = -1, s = 0;for(int j = 0; j < n; ++j)if(i >> j & 1) {s |= 1 << a[j].id;x = a[j].x, y = a[j].y, p = j;}for(int j = p + 1; j < n; ++j)f[i | (1 << j)] = 1LL * f[i] * get(a[j].x - x, a[j].y - y) % MOD;g[s] = 1LL * f[i] * get(h - x, w - y) % MOD;}for(int i = 0; i < n; ++i)for(int j = 0; j < (1 << n); ++j)if(~j >> i & 1)g[j] = (g[j] + MOD - g[j ^ (1 << i)]) % MOD;for(int i = 0; i < n; ++i)for(int j = 0; j < (1 << n); ++j)if(j >> i & 1)g[j] = (g[j] + g[j ^ (1 << i)]) % MOD;int u = (1 << n) - 1;for(int i = 0; i < (1 << n); ++i)printf("%d\n", g[u ^ i]);return 0;}