A. Archmage

Codeforces
IDCF10262A
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Archmage (AM for short) is a hero unit in WatercraftⅢ. He has $n$ mana *at most* and two powerful skills which enable him to show great strength in battle: Since the power of an Archmage is tremendous, the upper limit of mana $n$ is always greater than or equal to $x + y$. Every second, Archmage will summon *exactly one* Water Element (if the mana is enough, i.e., his mana won't be less than $0$ after that) or do nothing. Then no matter what he did before, he will restore $y$ mana. Archmage has $n$ mana at the end of the second $0$, and the game starts at the beginning of the second $1$. He wants to know how many Water Elements he can summon at most before the end of the second $m$. The input consists of multiple test cases. The first line contains a single integer $t (1 <= t <= 10^5)$, indicating the number of test cases. Each of the next $t$ lines contains $4$ integers $n, m, x, y (1 <= m, x, y <= 10^9, x + y <= n <= 2 times 10^9)$. For each test case, output the answer in a line. In test case $1$, Archmage can cast spells every second, so the answer is $2$. In test case $2$, here's a way for Archmage to cast spells $3$ times. Second $1$: Archmage cast spells, and there is $4 -x + y = 3$ mana left. Second $2$: Archmage cast spells, and there is $3 -x + y = 2$ mana left. Second $3$: Archmage cast spells, and there is $2 -x + y = 1$ mana left. Second $4$: Archmage doesn't have enough mana so he can do nothing, and there is $1 + y = 2$ mana left. ## Input The input consists of multiple test cases. The first line contains a single integer $t (1 <= t <= 10^5)$, indicating the number of test cases.Each of the next $t$ lines contains $4$ integers $n, m, x, y (1 <= m, x, y <= 10^9, x + y <= n <= 2 times 10^9)$. ## Output For each test case, output the answer in a line. [samples] ## Note In test case $1$, Archmage can cast spells every second, so the answer is $2$.In test case $2$, here's a way for Archmage to cast spells $3$ times.Second $1$: Archmage cast spells, and there is $4 -x + y = 3$ mana left.Second $2$: Archmage cast spells, and there is $3 -x + y = 2$ mana left.Second $3$: Archmage cast spells, and there is $2 -x + y = 1$ mana left.Second $4$: Archmage doesn't have enough mana so he can do nothing, and there is $1 + y = 2$ mana left.
**Definitions** Let $ T \in \mathbb{Z} $ be the number of test cases. For each test case, let $ N, M, X, Y \in \mathbb{Z} $ denote: - $ N $: number of rows, - $ M $: number of columns, - $ (X, Y) $: coordinates of Mr. Manohar’s office. The auto follows the path: - From $ (1,1) $ to $ (1,M) $ along row 1 (eastward), - Then from $ (1,M) $ to $ (N,M) $ along column $ M $ (southward). At $ t = 0 $, four secret agents start at $ (X, Y) $ and move in fixed directions with rebound behavior: - Agent 1: North (if possible), else South. - Agent 2: South (if possible), else North. - Agent 3: East (if possible), else West. - Agent 4: West (if possible), else East. Each agent moves 1 cell per second; upon hitting a grid boundary, it reverses direction immediately. **Constraints** 1. $ 1 \le T \le 1000 $ 2. $ 2 \le N, M \le 10^9 $ 3. $ 1 \le X \le N $, $ 1 \le Y \le M $ **Objective** Determine if the auto’s path intersects any secret agent at the same cell at the same time $ t \in \mathbb{Z}_{\ge 0} $. The auto’s position at time $ t $: - For $ 0 \le t < M $: $ (1, 1 + t) $ - For $ M \le t \le M + N - 1 $: $ (1 + (t - M), M) $ Let $ A_i(t) $ denote the position of agent $ i \in \{1,2,3,4\} $ at time $ t $. **Output** Print "Farewell" if $ \forall t \in [0, M + N - 1] $, auto’s position $ \neq A_i(t) $ for all $ i \in \{1,2,3,4\} $. Otherwise, print "BestWishes".
API Response (JSON)
{
  "problem": {
    "name": "A. Archmage",
    "description": {
      "content": "Archmage (AM for short) is a hero unit in WatercraftⅢ. He has $n$ mana *at most* and two powerful skills which enable him to show great strength in battle: Since the power of an Archmage is tremendo",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10262A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Archmage (AM for short) is a hero unit in WatercraftⅢ.\n\nHe has $n$ mana *at most* and two powerful skills which enable him to show great strength in battle:\n\nSince the power of an Archmage is tremendo...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case, let $ N, M, X, Y \\in \\mathbb{Z} $ denote:  \n- $ N $: number of rows,  \n- $ M $: number of columns,  \n- $ (...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments