結果
| 問題 |
No.936 Are
|
| コンテスト | |
| ユーザー |
mkawa2
|
| 提出日時 | 2022-05-19 00:53:00 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 2,783 ms / 3,000 ms |
| コード長 | 3,014 bytes |
| コンパイル時間 | 225 ms |
| コンパイル使用メモリ | 82,172 KB |
| 実行使用メモリ | 81,412 KB |
| 最終ジャッジ日時 | 2024-09-17 05:11:27 |
| 合計ジャッジ時間 | 25,979 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 |
ソースコード
import sys
sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
md = 10**9+7
# md = 998244353
from collections import defaultdict
def pack(aa):
if aa[0] == aa[1] == 0: return aa[-1]
if aa[2] == aa[3] == 0: return aa[-1]
res = 0
for a in aa: res = res*5+a
return res
def move(l, r, s, t):
def push(l, r, x, y):
x %= 5
y %= 5
i = 1
if x == y == 0: i = 0
elif l*r == 0 and (l+r+x == 5 or l+r+y == 5): i = 2
res[i].append((l, r, x, y))
res = [[], [], []]
if s and l: push(l, r, s+l, t)
if t and l: push(l, r, s, t+l)
if s and r: push(l, r, s+r, t)
if t and r: push(l, r, s, t+r)
for a in range(5):
if a > l+r: break
b = (l+r-a)%5
if a == b == 0 or a == l or a == r: continue
push(a, b, s, t)
return res
n, k = LI()
l1, r1, l2, r2 = LI()
to = defaultdict(list)
for b in range(5):
for a in range(5):
if a == b == 0: continue
for d in range(5):
for c in range(5):
if c == d == 0: continue
u0 = pack([a, b, c, d, 0])
u1 = pack([c, d, a, b, 1])
ret = move(a, b, c, d)
# pDB(a, b, c, d, u0, u1, ret)
if ret[0]:
for l, r, s, t in ret[0]:
v1 = pack([l, r, s, t, 1])
v0 = pack([s, t, l, r, 0])
to[u0].append(v1)
to[u1].append(v0)
for l, r, s, t in ret[1]:
v1 = pack([l, r, s, t, 1])
to[u0].append(v1)
elif ret[1]:
for l, r, s, t in ret[1]:
v1 = pack([l, r, s, t, 1])
v0 = pack([s, t, l, r, 0])
to[u0].append(v1)
to[u1].append(v0)
else:
for l, r, s, t in ret[2]:
v0 = pack([s, t, l, r, 0])
to[u1].append(v0)
# pDB(to)
dp = defaultdict(int)
u = pack([l1, r1, l2, r2, n])
dp[u] = 1
# pDB(dp)
ans = 0
for _ in range(k):
ndp = defaultdict(int)
for u, c in dp.items():
# pDB(u,c,to[u])
for v in to[u]:
ndp[v] = (ndp[v]+c)%md
dp = ndp
ans += dp[1]
ans %= md
# pDB(ans, dp)
print(ans)
mkawa2