#P4914. Dragon Gem Bullet-Hell Safety

    ID: 18155 Type: Default 1000ms 256MiB

Dragon Gem Bullet-Hell Safety

Dragon Gem Bullet-Hell Safety

In this problem, five dragon gems are arranged in a regular pentagon with circumradius r (i.e. the vertices of the pentagon lie on a circle of radius r). One of these gems, named aa, is located on the line connecting the circumcenter of the pentagon and the protagonist, Kaguya (i.e. Huiye). The circumcenter itself rotates clockwise around Huiye along a circle of radius R at speed v (and does not rotate on its own). Every t seconds, all five gems simultaneously fire a round of bullets. Each round consists of k bullets equally spaced in angle.

The twist is that the bullet pattern is decided by the following rule. Normally one might aim a bullet toward Huiye, but for gem aa the bullet that would normally be aimed toward Huiye is instead reversed (i.e. fired in the opposite direction, so that its front is facing away from Huiye). All of the other four gems copy the bullet directions used by gem aa. We assume the bullets travel with infinite speed (i.e. they are instantaneous). As a result, if any bullet ray passes through Huiye it will hit her. Your task is to decide whether Huiye is safe (i.e. no bullet eventually passes through her) or not.

Geometric details:

  • At any firing moment, the pentagon’s circumcenter is at some point C with |C| = R. By a suitable choice of coordinate system, you may assume that at the moment of a shot, C is at (R, 0) and Huiye is at the origin (0, 0).
  • Gem aa is the vertex lying on the line from C to the origin. Thus its position is (R − r, 0).
  • The remaining four gems are the other vertices of the pentagon. If we number the vertices from 0 to 4 with vertex 0 being gem aa, then for j = 0, 1, 2, 3, 4 the position of the j-th gem is:
    Pj = C + (r · (cos(π + 2πj/5), sin(π + 2πj/5))).
  • The bullet firing directions are determined solely by gem aa. Normally, a full round would have the bullets fired at angles

Consider the following bullet pattern: let the base angle be the direction in which aa fires the bullet that is reversed with respect to Huiye. Since gem aa lies on the line from C to the origin, the vector from gem aa to the origin is along the negative x‑axis (angle π). Then firing in the opposite direction gives a base angle of 0. The k bullet directions (for all gems) are defined as:

$$\theta_i = \frac{2\pi i}{k}, \quad i = 0, 1, \ldots, k-1.$$

Important note: Although gem aa would normally have a bullet aimed (if following the evenly spaced pattern) in the direction toward Huiye, that bullet is replaced by one fired in the opposite direction. Thus, for gem aa no bullet is ever fired in the direction of Huiye. However, the other four gems do fire bullets in all the directions listed above. A bullet fired from a gem at position P along a direction d will hit Huiye (the origin) if and only if the ray starting at P in direction d passes through the origin.

Let Dj be defined for a gem (other than aa) with index j (where j = 1,2,3,4) as follows. Note that the j-th gem’s position is:

$$P_j = C + (r \cos(\pi+\tfrac{2\pi j}{5}),\; r \sin(\pi+\tfrac{2\pi j}{5})).$$

Then, the vector from Pj to Huiye (the origin) is:

$$-P_j = -C - r \bigl(\cos(\pi+\tfrac{2\pi j}{5}),\; \sin(\pi+\tfrac{2\pi j}{5})\bigr).$$

Simplify using \(\cos(\pi+\alpha)=-\cos\alpha\) and \(\sin(\pi+\alpha)=-\sin\alpha\):

$$-P_j = -C + r \bigl(\cos(\tfrac{2\pi j}{5}),\; \sin(\tfrac{2\pi j}{5})\bigr) = e^{i\theta}\Bigl(r\,e^{\tfrac{2\pi i j}{5}}-R\Bigr).$$

The bullet fired from this gem in a given direction (one of the \(\theta_i\)) will hit Huiye if and only if the unit vector in the direction of \(-P_j\) equals one of the bullet directions. In other words, letting

$$\text{dir}(P_j) = \frac{r\,e^{\tfrac{2\pi i j}{5}}-R}{\left|r\,e^{\tfrac{2\pi i j}{5}}-R\right|},$$

Huiye is hit if there exist an index j in {1,2,3,4} and an integer i (0 ≤ i < k) such that

$$\text{arg}\Bigl(r\,e^{\tfrac{2\pi i j}{5}}-R\Bigr) = \frac{2\pi i}{k} \quad (\text{mod }2\pi).$$

Your task is to write a program that reads the parameters and determines if Huiye is safe (i.e. safe) or if she will be hit (unsafe).


Input Format:

The input consists of a single line containing five numbers:

  • R (a real number): the radius of the path along which the pentagon’s circumcenter rotates.
  • r (a real number): the circumradius of the pentagon formed by the dragon gems.
  • v (a real number): the speed of the circumcenter along its circular path.
  • t (a real number): the time interval between consecutive bullet rounds.
  • k (an integer): the number of bullets in one round.

Output Format:

Output a single word: safe if Huiye is never hit by a bullet, or unsafe if there exists at least one round in which a bullet (from a gem other than aa) is fired directly toward Huiye.


Note: Although the parameters v and t are provided, they do not affect the geometric condition under consideration and may be ignored in the safety computation.

Technical Details:

  • For gem aa (vertex 0) the bullet that would normally travel toward Huiye (if it existed) is replaced, so it does not count as a threat.
  • For each of the other four gems (indexed j = 1, 2, 3, 4), if the angle of the vector D(j) = r·e^(2πi·j/5) − R (when expressed in polar form) equals one of the angles \(\frac{2\pi i}{k}\) (for some integer i with 0 ≤ i < k), then Huiye will be hit (output unsafe).

You may assume that any equality comparisons between angles are to be made within an absolute error of \(10^{-6}\).

inputFormat

The input consists of a single line containing five numbers: R r v t k, where R, r, v, and t are real numbers and k is an integer.

outputFormat

Output a single line with either safe or unsafe (without quotes) depending on whether Huiye avoids being hit or not.

sample

10 5 1 1 4
safe

</p>