結果

問題 No.936 Are
ユーザー vwxyzvwxyz
提出日時 2024-04-25 03:42:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,900 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 20,056 KB
最終ジャッジ日時 2024-04-25 03:42:53
合計ジャッジ時間 5,422 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
11,392 KB
testcase_01 AC 26 ms
11,008 KB
testcase_02 RE -
testcase_03 AC 440 ms
16,112 KB
testcase_04 AC 645 ms
20,056 KB
testcase_05 AC 260 ms
13,676 KB
testcase_06 AC 456 ms
16,636 KB
testcase_07 AC 224 ms
13,460 KB
testcase_08 AC 26 ms
11,136 KB
testcase_09 AC 476 ms
16,512 KB
testcase_10 AC 289 ms
13,944 KB
testcase_11 AC 457 ms
16,236 KB
testcase_12 AC 103 ms
12,032 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**8)
from functools import lru_cache

def attack(L1,R1,L2,R2):
    retu=[]
    if L1 and L2:
        retu.append(((L1+L2)%5,R2))
    if L1 and R2:
        retu.append((L2,(L1+R2)%5))
    if R1 and L2:
        retu.append(((R1+L2)%5,R2))
    if R1 and R2:
        retu.append((L2,(R1+R2)%5))
    return retu

def split(L,R):
    retu=[]
    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}:
                retu.append((l,r))
    return retu

def lose(L1,R1,L2,R2):
    if L2 and R2:
        return False
    s=L2+R2
    if (-s)%5 in (L1,R1):
        return True
    return False

@lru_cache(maxsize=None)
def solve(N,cnt,L1,R1,L2,R2):
    if (L1,R1)==(0,0):
        ans=0
    elif (L2,R2)==(0,0):
        ans=1
    elif cnt==K:
        ans=0
    else:
        ans=0
        if cnt%2!=N%2:
            if not (0,0) in attack(L2,R2,L1,R1):
                not_lose=False
                for L,R in split(L2,R2):
                    not_lose|=not lose(L1,R1,L,R)
                for L,R in attack(L2,R2,L1,R1):
                    not_lose|=not lose(L,R,L2,R2)

                for L,R in split(L2,R2):
                    if not_lose and lose(L1,R1,L,R):
                        continue
                    ans+=solve(N,cnt+1,L1,R1,L,R)
                for L,R in attack(L2,R2,L1,R1):
                    if not_lose and lose(L,R,L2,R2):
                        continue
                    ans+=solve(N,cnt+1,L,R,L2,R2)
        else:
            for L,R in split(L1,R1):
                ans+=solve(N,cnt+1,L,R,L2,R2)
            for L,R in attack(L1,R1,L2,R2):
                ans+=solve(N,cnt+1,L1,R1,L,R)
        ans%=mod
    return ans

N,K=map(int,input().split())
mod=10**9+7
L1,R1,L2,R2=map(int,input().split())
ans=solve(N,0,L1,R1,L2,R2)
print(ans)
0