結果
問題 | No.767 配られたジャパリまん |
ユーザー |
|
提出日時 | 2024-10-15 22:47:08 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 282 ms / 2,000 ms |
コード長 | 1,607 bytes |
コンパイル時間 | 2,372 ms |
コンパイル使用メモリ | 196,204 KB |
最終ジャッジ日時 | 2025-02-24 19:55:23 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 15 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:43:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 43 | scanf("%d%d%d", &h, &w, &n); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:45:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 45 | scanf("%d%d", &a[i].x, &a[i].y); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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; }