Herbert
Time limit1sMemory limit128 MB
Count distinct squares a robot starting at the origin can end on within n moves when each step or ninety-degree turn costs one move.
- Level
Medium5 of 10
- Topics
- Math, Combinatorics
- Solved
- No attempts yet
Problem
Herbert is a game where you drive one robot across an infinite two dimensional grid. Three commands are available.
s: move one square forward in the direction the robot currently faces.l: turn ninety degrees counterclockwise without leaving the square.r: turn ninety degrees clockwise without leaving the square.
Every command spends one move, turns included. The robot starts at the origin facing one fixed direction.
After playing for a while you start to wonder how many squares the robot can reach once the number of moves is capped. Given a budget of at most moves, count the distinct squares the robot can end up on.
Input
The first line has an integer (), the number of test cases.
Each of the next lines has one integer (), the largest number of moves allowed in that test case.
Output
For each test case, print the number of reachable squares on its own line.