Created
December 26, 2017 10:39
-
-
Save maksverver/ca72a2c9dfc3fcdefba0e9df40fdc535 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
import sys | |
N = int(sys.stdin.readline()) | |
grid = defaultdict(lambda: 0) | |
grid[0, 0] = 1 | |
x, y = 0, 0 | |
dx, dy = 1, 0 | |
while grid[x, y] <= N: | |
x += dx | |
y += dy | |
grid[x, y] = sum( | |
grid[nx, ny] | |
for nx in (x - 1, x, x + 1) | |
for ny in (y - 1, y, y + 1)) | |
if grid[x - dy, y + dx] == 0: | |
dx, dy = -dy, dx | |
print(grid[x, y]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment