結果

問題 No.2655 Increasing Strides
ユーザー eloy
提出日時 2024-03-01 22:45:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,062 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 82,520 KB
実行使用メモリ 158,040 KB
最終ジャッジ日時 2024-09-29 14:37:54
合計ジャッジ時間 5,955 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 11 WA * 4 TLE * 1 -- * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import sys
input = sys.stdin.readline

############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

def increasing_strides(max):
    cache = defaultdict(bool)

    def worker(x, y, i, dir):
        if x == 0 and y == 0:
            return True
        elif i == max:
            return False
        elif cache.get((x, y, i, dir)):
            return cache[(x, y, i, dir)]
        else:
            if dir == 0 or dir == 180:
                cache[(x + i, y, i+1, 270)] = worker(x + i, y, i+1, 270)
                cache[(x - i, y, i+1, 90)] = worker(x - i, y, i+1, 90)
            elif dir == 90 or dir == 270:
                cache[(x, y + i, i+1, 0)] = worker(x, y+i, i+1, 0)
                cache[(x, y - i, i+1, 180)] = worker(x, y-i, i+1, 180)

    worker(0, 1, 1, 0)

n = inp()
print("Yes" if increasing_strides(n) else "No")
0