Solution (source code)

= Solution

For $p=1/4$, put $|\psi_{\rm in}\rangle=\tfrac12|g\rangle+\tfrac{\sqrt3}{2}|b\rangle$. After the first phase rotation the state is
$$
|v\rangle=\frac{e^{i\phi}}2|g\rangle+\frac{\sqrt3}2|b\rangle,
\qquad
\langle\psi_{\rm in}|v\rangle=\frac{e^{i\phi}+3}{4}.
$$
Since $UR_{00}^\pi U^\dagger=I-2|\psi_{\rm in}\rangle\langle\psi_{\rm in}|$, the requested state is
$$
\frac{e^{i\phi}-3}{4}|g\rangle
-\frac{\sqrt3(e^{i\phi}+1)}4|b\rangle.
$$
It is proportional to $|g\rangle$ exactly when $e^{i\phi}=-1$, hence when $\phi=\pi$. The state is then $-|g\rangle$, whose <global phase> has no physical effect.