結果
| 問題 |
No.936 Are
|
| コンテスト | |
| ユーザー |
vwxyz
|
| 提出日時 | 2024-04-25 03:44:58 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,868 bytes |
| コンパイル時間 | 448 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 227,072 KB |
| 最終ジャッジ日時 | 2024-11-07 13:35:38 |
| 合計ジャッジ時間 | 5,076 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 TLE * 1 -- * 22 |
ソースコード
import sys
sys.setrecursionlimit(10**8)
from functools import lru_cache
import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')
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):
return 0
if (L2,R2)==(0,0):
return 1
if cnt==K:
return 0
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)
vwxyz