QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#20979. 轍にはまる

Statistics

Farmer John が最近農場を拡大し、牛たちには今や実質的に無限の大きさに見えています!放牧地は正方形の「マス」からなる無限の二次元格子で、各マスにはおいしい草が生えています(無限のチェス盤のマスと考えてください)。$N$ 頭の牛($1\le N\le 50$)はそれぞれ異なるマスから出発し、北向きの牛と東向きの牛がいます。

毎時間、各牛は次のどちらかを行います。

  • 現在のマスの草がすでに別の牛に食べられていたら止まります。
  • 現在のマスの草をすべて食べ、向いている方向に一マス進みます。

そのため、時間とともに各牛の後ろには空のマスからなる不毛な「轍」が残ります。

二頭が同じ移動で同じ草のあるマスに入った場合は、そのマスを共有し、次の時間にそれぞれの方向へ進み続けます。

各牛が食べる草の量を求めてください。止まらない牛は無限の量の草を食べます。

入力

最初の行には $N$ が与えられます。続く $N$ 行は各牛の出発位置を、文字 N(北向き)または E(東向き)と、マスの座標を表す非負整数 $x$ と $y$($0\le x\le 10^9$、$0\le y\le 10^9$)で記述します。すべての $x$ 座標は互いに異なり、$y$ 座標も同様です。

方向と座標を明確にすると、$(x,y)$ の牛が北へ進むと $(x,y+1)$ に着き、東へ進むと $(x+1, y)$ に着きます。

出力

$N$ 行を出力してください。$i$ 行目は入力の $i$ 番目の牛が何マス分の草を食べるかを表します。無限に食べる牛については Infinity を出力してください。

入出力例

入力 1

6
E 3 5
N 5 3
E 4 6
E 10 4
N 11 2
N 8 1

出力 1

5
3
Infinity
Infinity
2
5

小課題

  • テストケース $2$ から $5$ ではすべての座標が高々 $100$ です。
  • テストケース $6$ から $10$ に追加の制約はありません。

問題作成者:Brian Dean

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.