We induct on $|D|$.
Base Case: $|D|=1$, clear.
Inductive Step: let $D=\{d_1,\cdots,d_k\}$. Let $md=\gcd(d_1,\cdots,d_{k-1}), nd=d_k$ and thus $d=\gcd(md,d_k)=\gcd(md,nd)$ so $\gcd(m,n)=1$.
By Inductive hypothesis, there exists a bijection $g$ such that $|g(n+1)-g(n)| \in \{d_1,\cdots,d_{k-1} \}$.
Consider an infinite grid $q(x,y)$ where $0\le x\le m-1, y\in \mathbb{Z}$ such that $q(0,t)=g(t)$ for $t\in \mathbb{Z}$, $q(x,y)=q(x-1,y)+nd$ for all $x,y\in \mathbb{Z}, 1\le x\le m-1$.
Note every multiple of $d$ is listed exactly once in the columns $x=0,1,\cdots,n-1$ because they form $md\mathbb{Z} + \{0,nd,\cdots,(m-1)nd\}$ and $\gcd(m,n)=1$. If a multiple of $d$ shows up twice, then it must show up twice in the same column, which means that $g$ is not a bijection
We can have $f(a)$, $f(a+1)$ take values of any two points with distance 1 because $q(x,y)-q(x-1,y)=nd=d_k$ and $q(x,y)-q(x,y-1)=q(0,y)-q(0,y-1)=g(t)-g(t-1) \in \{d_1,\cdots,d_k\}$ by inductive hypothesis. like $(0,0)\to (0,1)\to \cdots \to (0,m-1) \to (1,m-1) \to (1,m-2) \to \cdots \to (1,0) \to (2,0) \to \cdots$ and note zigzagging goes up and down, completing the induction.