Not lifting your pen on the $n\times n$ grid

I believe this is a proof that you can't do better than $2n-2$:

Let $m$ be the number of horizontal and vertical lines in the path. Then, since there are $2n$ rows and columns, there are $2n-m$ rows and columns that don't contain a line along their length; say, $k$ rows and $l$ columns with $k+l=2n-m$. Imagine the grid points where these rows and columns intersect taken out of the grid and arranged in a rectangle of $k$ rows and $l$ columns. Since each of the points in this rectangle is both in a row and in a column that doesn't contain a line along its length, each of these points must be on some line that is neither horizontal nor vertical.

If $k=0$, then we have $n$ horizontal lines, and these must be connected by at least $n-1$ non-horizontal lines to make an unbroken path. Thus, for $k=0$ there must be $2n-1$ lines, so we can exclude that case.

If $k=1$, then we have $n-1$ horizontal lines, and we have to connect each of the $n$ grid points on the remaining row with a separate line, so again we must have at least $2n-1$ lines, so we can exclude that case.

Thus $k\ge2$, and likewise $l\ge2$. Thus we may consider the border of the rectangle, i.e. the two outermost rows and the two outermost columns. This border consists of $2k+2l-4=2(k+l-2)=2(2n-m-2)$ grid points. Every line that doesn't run along the length of one of these rows or columns can hit at most two of these points. That means there must be at least $2n-m-2$ lines in addition to the $m$ horizontal and vertical lines, for a total of $2n-2$.

P.S.: You can check this out in the $8\times8$ and $10\times10$ solutions linked to in the question -- in each case, the "rectangle" constructed in the proof is actually a contiguous rectangle in the grid (with $k=6$, $l=8$ and $k=10$, $l=2$, respectively), and you can see that the path optimally connects two points of that rectangle's border with each line that isn't horizontal or vertical.


Since I have to explain Joriki's solution to all the people I mentioned the problem to, I decided to provide a typed solution written up in my own words. Although there are no new ideas, there doesn't seem to be any good reason not to just share it anyway:

Lemma Let $a\geq 1$, $b\geq 1$. Given an $a\times b$ rectangular grid, without using horizontal or vertical lines it requires at least $a+b-2$ lines to cover all the points. (Here the path need not be connected)

proof: Consider the exterior of the grid. If $a\geq 2$ and $b\geq 2$ then each diagonal line can cover at most two points, but there are $2a+2b-4$ points that must be covered. If $b=1$ then each diagonal line covers at most 1 point, and hence we need $a=a+b-1>a+b-2$ lines. Similarly if $a=1$.

Given a solution to the $n\times n$ grid, let $h$ be the number of horizontal lines, and $v$ be the number of vertical lines used. If $h=n$, we must have at least $2n-1$ lines since it will take at least $n-1$ lines to connect all of these horizontal parts. Similarly for $v=n$.

Now, let $v<n$, $h<n$ and remove all the rows and columns where a horizontal or vertical line appears. Then we have an $n-h\times n-v$ grid left over, which by the lemma requires at least $(n-h)+(n-v)-2=2n-2-h-v$ lines to cover. Since we already used $h+v$ lines, the entire grid requires $(h+v)+(2n-2-h-v)=2n-2$ lines, and the proof is complete.