結果
問題 | No.767 配られたジャパリまん |
ユーザー |
|
提出日時 | 2018-12-15 17:46:36 |
言語 | D (dmd 2.109.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,006 bytes |
コンパイル時間 | 1,171 ms |
コンパイル使用メモリ | 126,060 KB |
実行使用メモリ | 27,200 KB |
最終ジャッジ日時 | 2024-06-13 02:22:24 |
合計ジャッジ時間 | 6,019 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 14 TLE * 1 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;import std.typecons, std.range, std.random, std.math, std.container;import std.numeric, std.bigint, core.bitop, core.stdc.string;immutable long MOD = 10^^8 + 7;immutable long MAX = 2 * 10^^5 + 10;long[MAX] F;long[1<<20] all; // all[S]: 集合Sに含まれる座標をすべて通る経路数long[1<<20] any; // any[S]: 集合Sに含まれる座標のうち少なくとも1つは通る経路数void main() {auto s = readln.split.map!(to!int);auto H = s[0];auto W = s[1];auto K = s[2];auto P = K.iota.map!(i => readln.split.map!(to!int).array ~ i).array;P.sort();F[0] = 1;foreach (i; 1..MAX) F[i] = F[i-1] * i % MOD;all[0] = comb(H+W, H);outer: foreach (mask; 1..(1<<K)) {auto A = [0, 0, -1] ~ (K.iota.filter!(i => mask & (1 << P[i][2])).map!(i => P[i]).array) ~ [H, W, -1];long tmp = 1;foreach (i; 0..A.length.to!int-1) {if (A[i][1] > A[i+1][1]) {continue outer;}tmp *= comb(A[i+1][0] - A[i][0] + A[i+1][1] - A[i][1], A[i+1][0] - A[i][0]);tmp %= MOD;}all[mask] = tmp;}for (int mask = 0; mask < (1<<K); ++mask) {int sign = mask.popcnt % 2 ? -1 : 1;any[mask] = mask.popcnt % 2 ? -all[mask] : all[mask];}for (int i = 0; i < K; ++i) {for (int mask = 0; mask < (1<<K); ++mask) {if (mask & (1 << i)) {any[mask] += any[mask ^ (1 << i)];any[mask] %= MOD;}}}foreach (i; 0..(1<<K)) {writeln((any[i] % MOD + MOD) % MOD);}}long comb(long n, long r) {if (n < r) return 0;return F[n] * powmod(F[n-r], MOD-2, MOD) % MOD * powmod(F[r], MOD-2, MOD) % MOD;}long powmod(long a, long x, long m) {long ret = 1;while (x) {if (x % 2) ret = ret * a % m;a = a * a % m;x /= 2;}return ret;}