結果

問題 No.936 Are
ユーザー mkawa2mkawa2
提出日時 2022-05-19 00:53:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,820 ms / 3,000 ms
コード長 3,014 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 81,484 KB
実行使用メモリ 80,828 KB
最終ジャッジ日時 2023-10-17 06:33:28
合計ジャッジ時間 27,452 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
76,232 KB
testcase_01 AC 99 ms
76,404 KB
testcase_02 AC 2,820 ms
80,828 KB
testcase_03 AC 120 ms
76,448 KB
testcase_04 AC 122 ms
76,352 KB
testcase_05 AC 107 ms
76,304 KB
testcase_06 AC 110 ms
76,284 KB
testcase_07 AC 108 ms
76,328 KB
testcase_08 AC 88 ms
75,892 KB
testcase_09 AC 118 ms
76,452 KB
testcase_10 AC 100 ms
76,236 KB
testcase_11 AC 112 ms
76,316 KB
testcase_12 AC 101 ms
76,272 KB
testcase_13 AC 744 ms
77,580 KB
testcase_14 AC 2,293 ms
79,920 KB
testcase_15 AC 989 ms
77,696 KB
testcase_16 AC 1,467 ms
78,876 KB
testcase_17 AC 1,322 ms
78,576 KB
testcase_18 AC 687 ms
77,400 KB
testcase_19 AC 2,309 ms
80,224 KB
testcase_20 AC 2,305 ms
80,332 KB
testcase_21 AC 2,421 ms
80,320 KB
testcase_22 AC 1,318 ms
78,548 KB
testcase_23 AC 2,431 ms
80,560 KB
testcase_24 AC 2,424 ms
80,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0