結果

問題 No.767 配られたジャパリまん
ユーザー ikd
提出日時 2018-12-25 16:37:37
言語 Nim
(2.2.0)
結果
AC  
実行時間 1,746 ms / 2,000 ms
コード長 1,737 bytes
コンパイル時間 3,679 ms
コンパイル使用メモリ 66,832 KB
実行使用メモリ 18,280 KB
最終ジャッジ日時 2024-07-01 06:16:12
合計ジャッジ時間 7,595 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import strutils, sequtils, algorithm
proc popcount[T: int64|int](a: T): cint {.importc: "__builtin_popcountl",
nodecl, nosideeffect.}
const MOD = 1_000_000_00+7
proc powmod(b, e: int64): int64 =
if e==0:
result = 1
elif e==1:
result = b
elif e mod 2 == 0:
result = powmod(b*b mod MOD, e div 2)
else:
result = b*powmod(b, e-1) mod MOD
var
fac: seq[int64]
inv: seq[int64]
proc make(n: int) =
fac = @[1'i64]
inv = @[1'i64]
for i in 1..<n:
fac.add(fac[i-1]*i mod MOD)
inv.add(powmod(fac[i], MOD-2))
proc cmb(n, r: int): int64 =
if r<0 or n<r:
result = 0
else:
result = fac[n]*inv[r] mod MOD
result = result*inv[n-r] mod MOD
proc main() =
let
hwk = stdin.readLine.split.map(parseInt)
(h, w, k) = (hwk[0], hwk[1], hwk[2])
ab = (0..<k).mapIt(stdin.readLine.split.map(parseInt))
make(h+w+1)
var abi = newSeqWith(k, newSeq[int]())
for i in 0..<k:
abi[i] = @[ab[i][0], ab[i][1], i]
abi.sort do (p, q: seq[int])->int:
result = cmp(p[0], q[0])
if result==0:
result = cmp(p[1], q[1])
var dp = newSeqWith(1 shl k, 1'i64)
for bits in 0..<(1 shl k):
var
cur_y = 0
cur_x = 0
for p in abi:
if (bits and (1 shl p[2]))>0:
let
dy = p[0]-cur_y
dx = p[1]-cur_x
dp[bits] = dp[bits]*cmb(dy+dx, dy) mod MOD
cur_y = p[0]
cur_x = p[1]
dp[bits] = dp[bits]*cmb((h-cur_y)+(w-cur_x), h-cur_y) mod MOD
for i in 0..<k:
for bits in 0..<(1 shl k):
if (bits and (1 shl i))==0:
dp[bits xor (1 shl i)] = (dp[bits xor (1 shl i)]+(MOD-dp[
bits])) mod MOD
for bits, x in dp:
if popcount(bits) mod 2 == 0:
echo x
else:
echo MOD-x
main()
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0