結果

問題 No.936 Are
ユーザー vwxyzvwxyz
提出日時 2024-04-25 04:25:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,870 ms / 3,000 ms
コード長 2,830 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 79,696 KB
最終ジャッジ日時 2024-04-25 04:26:07
合計ジャッジ時間 31,920 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
77,784 KB
testcase_01 AC 2,619 ms
79,696 KB
testcase_02 AC 2,834 ms
79,572 KB
testcase_03 AC 204 ms
77,820 KB
testcase_04 AC 201 ms
78,200 KB
testcase_05 AC 192 ms
78,196 KB
testcase_06 AC 213 ms
78,800 KB
testcase_07 AC 186 ms
77,828 KB
testcase_08 AC 184 ms
78,412 KB
testcase_09 AC 228 ms
79,060 KB
testcase_10 AC 227 ms
78,804 KB
testcase_11 AC 205 ms
78,128 KB
testcase_12 AC 148 ms
77,128 KB
testcase_13 AC 917 ms
78,704 KB
testcase_14 AC 2,166 ms
79,444 KB
testcase_15 AC 1,039 ms
77,948 KB
testcase_16 AC 1,644 ms
78,708 KB
testcase_17 AC 1,525 ms
79,184 KB
testcase_18 AC 727 ms
78,072 KB
testcase_19 AC 2,571 ms
79,224 KB
testcase_20 AC 2,606 ms
78,720 KB
testcase_21 AC 2,315 ms
78,712 KB
testcase_22 AC 1,483 ms
78,932 KB
testcase_23 AC 2,870 ms
78,972 KB
testcase_24 AC 2,869 ms
79,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

attack=[]
lose=[]
for L1 in range(5):
    for R1 in range(5):
        for L2 in range(5):
            for R2 in range(5):
                attack.append([])
                if L1 and L2:
                    attack[-1].append(((L1+L2)%5,R2))
                if L1 and R2:
                    attack[-1].append((L2,(L1+R2)%5))
                if R1 and L2:
                    attack[-1].append(((R1+L2)%5,R2))
                if R1 and R2:
                    attack[-1].append((L2,(R1+R2)%5))

                if L2 and R2:
                    lose.append(False)
                else:
                    s=L2+R2
                    lose.append((-s)%5 in (L1,R1))

split=[]
for L in range(5):
    for R in range(5):
        split.append([])
        for l in range(5):
            for r in range(5):
                if (l,r)==(0,0):
                    continue
                if (l+r==L+R or l+r==(L+R)%5) and {l,r}!={L,R}:
                    split[-1].append((l,r))

N,K=map(int,input().split())
mod=10**9+7
def idx(L1,R1,L2,R2):
    return L1*125+R1*25+L2*5+R2
dp=[0]*625
for cnt in range(K,-1,-1):
    prev=dp
    dp=[0]*625
    for L1 in range(5):
        for R1 in range(5):
            for L2 in range(5):
                for R2 in range(5):
                    if (L1,R1)==(0,0):
                        dp[idx(L1,R1,L2,R2)]=0
                    elif (L2,R2)==(0,0):
                        dp[idx(L1,R1,L2,R2)]=1
                    else:
                        if cnt%2!=N%2:
                            if not (0,0) in attack[idx(L2,R2,L1,R1)]:
                                not_lose=False
                                for L,R in split[L2*5+R2]:
                                    not_lose|=not lose[idx(L1,R1,L,R)]
                                for L,R in attack[idx(L2,R2,L1,R1)]:
                                    not_lose|=not lose[idx(L,R,L2,R2)]

                                for L,R in split[L2*5+R2]:
                                    if not_lose and lose[idx(L1,R1,L,R)]:
                                        continue
                                    dp[idx(L1,R1,L2,R2)]+=prev[idx(L1,R1,L,R)]
                                for L,R in attack[idx(L2,R2,L1,R1)]:
                                    if not_lose and lose[idx(L,R,L2,R2)]:
                                        continue
                                    dp[idx(L1,R1,L2,R2)]+=prev[idx(L,R,L2,R2)]
                        else:
                            for L,R in split[L1*5+R1]:
                                dp[idx(L1,R1,L2,R2)]+=prev[idx(L,R,L2,R2)]
                            for L,R in attack[idx(L1,R1,L2,R2)]:
                                dp[idx(L1,R1,L2,R2)]+=prev[idx(L1,R1,L,R)]
                        dp[idx(L1,R1,L2,R2)]%=mod
L1,R1,L2,R2=map(int,input().split())
ans=dp[idx(L1,R1,L2,R2)]
print(ans)
0