A - Windy Drone Control (A) Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

問題文

高橋くんは二次元平面上で飛行ドローンを操作し、好きな順番で N 箇所の目的地を訪れたいと考えている。 東西方向に x 軸を、南北方向に y 軸を取る。 飛行区域は 2\cdot 10^5\times 2\cdot 10^5 の正方形で x=-10^5,x=+10^5,y=-10^5,y=+10^5 の4つの壁で囲まれている。 更に、これらの外周の壁以外にも内側に壁がある場合がある。

ドローンは位置 (x,y) と速度 (v_x,v_y) の状態を持つ。 位置と速度は常に整数値である。 位置 (s_x,s_y)、速度 (0,0) の初期状態から開始し、毎ターン以下の2種類の操作のどちらか一方を行うことが出来る。

  1. 加速: 整数ベクトル (a_x,a_y) を指定し、ドローンの速度を (v_x,v_y) から (v_x+a_x,v_y+a_y) に変化させる。a_x^2+a_y^2\leq 500^2 を満たす必要がある。
  2. 計測: 非零の整数ベクトル (b_x,b_y) を指定し、現在のドローンの位置 (x,y) から (b_x,b_y) 方向に最も近い壁までの距離を誤差付きで計測する。b_x^2+b_y^2\leq 10^{10} を満たす必要がある。(x,y) から (b_x,b_y) 方向へ半直線を延ばし((x+b_x,y+b_y) を通る)、最初にぶつかった壁の地点 (x',y') までのユークリッド距離を d=\sqrt{(x-x')^2+(y-y')^2} とする。得られる値は、入力で与えられるパラメータ \delta に対し、平均 1、標準偏差 \delta の正規分布からサンプルした値を \alpha として、\mathrm{round}(d\times \alpha) である。ただし \alpha\leq 0 の場合は \alpha をサンプルし直す。半直線が壁の端点を通る場合はぶつかったと判定される。ただし半直線が壁と平行な場合は除く。

操作後に風の影響でドローンの速度が (v_x,v_y) からランダムに微少量変化する。 入力で与えられるパラメータ \epsilon に対し、平均 0、標準偏差 \epsilon の正規分布から2つサンプルして四捨五入したものを (f_x,f_y) としたとき、速度は (v_x+f_x,v_y+f_y) となる。

各ターンの最後に、その時点での速度 (v_x,v_y) に応じて、現在位置が (x+v_x,y+v_y) に更新される。 ただし、二点 (x,y)(x+v_x,y+v_y) を結ぶ線分が、壁と共通部分を持つ場合(線分と壁が平行な場合も含む)、壁に衝突したとして現在位置の更新は行わず、速度を (0,0) に初期化する。 初期状態でドローンは壁と接していないことが保証されており、壁と衝突時は衝突前の位置に戻るため、壁に接した状態で移動が開始することはない。

壁に衝突しなかった場合、目的地への到達判定を行う。 二点 (x,y)(x+v_x,y+v_y) を結ぶ線分と、まだ訪れていない各目的地 (p_x,p_y) との距離が 1000 以下の場合、その目的地に到達したと判定される。 ここで、線分 S と点 p の距離とは、S 上の任意の点 qp の距離を考えた時の最小値として定義される。

最大で5000ターンまで操作を行うことが出来、全ての目的地を訪れた時点で操作は即座に完了する。

得点

初期状態でスコア 0 の状態から開始し、毎ターン以下のようにスコアが変動する。

  1. スコアが 2 減少する。
  2. 壁に衝突した場合は追加でスコアが 100 減少する。複数の壁に同時に衝突した場合にも減少量は 100 のみである。
  3. 初めて到達した目的地がある場合、1つにつき 1000 点が得られる。

5000ターンが経過するもしくは全ての目的地を訪れた時点までのうちで、最もスコアが高かった瞬間のスコアがテストケースに対する得点となる。

一つ以上のテストケースで不正な出力や制限時間超過をした場合、提出全体の判定がWATLEとなる。 各問題に対してコンテスト時間中に得た最高得点の総和で最終順位が決定され、コンテスト終了後のシステムテストは行われない。 同じ得点を複数の参加者が得た場合、提出時刻に関わらず同じ順位となる。

入出力

まずはじめに、以下の形式で標準入力から情報が与えられる。

N M \epsilon \delta
s_x s_y
p_{x,0} p_{y,0}
\vdots
p_{x,N-1} p_{y,N-1}
l_{x,0} l_{y,0} r_{x,0} r_{y,0}
\vdots
l_{x,M-1} l_{y,M-1} r_{x,M-1} r_{y,M-1}
  • 目的地の数は全ての問題において N=10 で固定である。
  • 外周以外の壁の数 M0\leq M\leq 10 を満たす。
  • (s_x,s_y) はドローンの初期位置を表し、-10^5< s_x,s_y< 10^5 を満たす。外周を含む壁と接していないことが保証されている。
  • (p_{x,i},p_{y,i})i 番目の目的地の座標を表し、-10^5\leq p_{x,i},p_{y,i}\leq 10^5 を満たす。目的地は壁と接している可能性がある。初期位置ならびに他の目的地との間の距離は 5000 以上であることが保証されている。
  • (l_{x,i},l_{y,i})(r_{x,i},r_{y,i})i 番目の壁の端点の座標を表し、-10^5\leq l_{x,i},l_{y,i},r_{x,i},r_{y,i}\leq 10^5 を満たす。壁は正の長さを持ち、外周以外の壁とは共通部分を持たないことが保証されている。また、外周との共通部分も1点以下であることが保証されている。これらの条件から、飛行区域内の全ての点は壁を通らずに行き来出来ることが保証される。

上記の情報を読み込んだら、以下の処理を最大で 5000 ターン繰り返す。

加速を行う場合、加速度ベクトル (a_x,a_y) を、以下の形式で標準出力に出力せよ。

A a_x a_y

計測を行う場合、計測する方向 (b_x,b_y) を、以下の形式で標準出力に出力せよ。

S b_x b_y

計測を行った場合のみ、計測結果を表す整数値が標準入力から一行で与えられる。

出力の後には改行をし、更に標準出力を flush しなければならない。 そうしない場合、TLEとなる可能性がある。 全ての目的地を訪問後および、5000 回終了後のクエリに対してはジャッジプログラムは返答を行わないため、返答待ちをした場合には TLEとなる可能性があるので注意せよ。

ターンの終わりにドローンの移動結果の情報が以下の形式で標準入力から与えられる。

c h
q_0 \cdots q_{h-1}

c は壁に衝突したかどうかを表し、壁に衝突した場合は c=1、しなかった場合は c=0 である。どの壁に衝突したかの情報は得られない。 h はこのターンに初めて訪れた目的地の数を表し、次の行の各 q_i が初めて訪れた目的地の番号 (0\leq q_i\leq N-1) である。 h=0 の場合には、q_i の行は空行ではなくスキップされる。

t Output Input
事前情報
2 0 10.0 0.1
43722 -75332
79243 32532
44002 -77034
0
A 150 -400
0 0
1
S 0 1
168969
0 1
1
\vdots

入力生成方法

L 以上 U 以下の整数値を一様ランダムに生成する関数を \mathrm{rand}(L,U) で表す。 全ての問題で共通な部分を説明する。 各問題固有の部分については下記の「問題毎の違い」を参照せよ。

s の生成

s_x=\mathrm{rand}(-99999,99999)s_y=\mathrm{rand}(-99999,99999) により生成される。

p_{x,i} p_{y,i} の生成

i について順番に、 p_{x,i}=\mathrm{rand}(-100000,100000)p_{y,i}=\mathrm{rand}(-100000,100000) により生成し、既に生成した s(p_{x,j}, p_{y,j}) の中にユークリッド距離が 5000 以下のものがあれば生成し直す。

壁の生成

i について順番に以下のように生成する。

まず、l_{x,i}=\mathrm{rand}(-90000,90000)l_{y,i}=\mathrm{rand}(-90000,90000) を生成し、次に r_{x,i}'=l_{x,i}+\mathrm{rand}(-100000,100000)r_{y,i}'=l_{y,i}+\mathrm{rand}(-100000,100000) と設定する。 (l_{x,i},l_{y,i})=(r_{x,i}',r_{y,i}') の場合は i 番の壁の生成をやり直す。 r_{x,i}' が範囲外 (r_{x,i}'<-100000 もしくは 100000<r_{x,i}') かつ、r_{y,i}' も範囲外ならば i 番の壁の生成をやり直す。 そうでない場合、r_{x,i}=\min(100000,\max(-100000,r_{x,i}'))r_{y,i}=\min(100000,\max(-100000,r_{y,i}')) と設定する。 この壁 (l_{x,i},l_{y,i})-(r_{x,i},r_{y,i}) が既に生成した他の壁と共有点を持つ、もしくは初期位置 (sx,sy) がこの壁上にある場合には i 番の壁の生成をやり直す。 そうでない場合は、i 番の壁として採用する。

問題毎の違い

問題 テストケース数 M \epsilon \delta
A 60 0 \mathrm{rand}(1,100) \mathrm{rand}(1,20)\times 0.01
B 60 10 \mathrm{rand}(0,1) 0.01
C 80 \mathrm{rand}(1,10) \mathrm{rand}(1,100) \mathrm{rand}(1,20)\times 0.01

ツール(入力ジェネレータ・ローカルテスタ)

コンテスト期間中に、チーム外とのビジュアライズ結果の共有や解法・考察に関する言及は禁止されています。ご注意下さい。

ツールで用いられる入出力ファイルの仕様

ローカルテスタに与える入力ファイルは事前情報の末尾に以下の形式で乱数 \alpha(f_x,f_y) が含まれている。

\alpha_0
\vdots
\alpha_{4999}
f_{x,0} f_{y,0}
\vdots
f_{x,4999} f_{y,4999}

\alpha_tt ターン目に計測を行った場合の誤差であり、(f_{x,t},f_{y,t})t ターン目に風の影響で変化する速度である。

解答プログラムは、# から始まるコメント行を出力に含めても良い。 ジャッジプログラムはコメント行を全て無視するため、コメント行を出力するプログラムをそのまま提出可能である。 ローカルテスタは解答プログラムの出力に追加で毎ターン初めに以下のコメント行を出力する。

#p x y
#v v_x v_y

(x,y)(v_x,v_y) はそのターン開始時点におけるドローンの座標と速度である。

Problem Statement

Takahashi wants to operate a flying drone on a two-dimensional plane and visit N destinations in arbitrary order. Let x-axis be east-west and y-axis be north-south. The drone's flight area is a 2\cdot 10^5\times 2\cdot 10^5 square surrounded by four walls with x=-10^5,x=+10^5,y=-10^5,y=+10^5. Furthermore, in addition to these outer walls, there can exist other walls inside.

The drone has a state with position (x,y) and velocity (v_x,v_y). The position and velocity are always integer values. Starting from an initial state of position (s_x,s_y) and velocity (0,0), you can perform either of the following two types of operations each turn.

  1. Acceleration: Specify an integer vector (a_x,a_y) to change the velocity of the drone from (v_x,v_y) to (v_x+a_x,v_y+a_y). It must satisfy a_x^2+a_y^2\leq 500^2.
  2. Measurement: Specify a non-zero integer vector (b_x,b_y) and measure the distance from the current drone position (x,y) to the nearest wall in the (b_x,b_y) direction with uncertainty. It must satisfy b_x^2+b_y^2\leq 10^{10}. Extend a ray from the point (x, y) in the direction towards (b_x, b_y) (the ray passing through (x+b_x,y+b_y)) and calculate the Euclidean distance d = \sqrt{(x-x')^2 + (y-y')^2} to the point (x', y') where it first intersects a wall. The resulting value is \mathrm{round}(d\times \alpha), where \alpha is a value sampled from a normal distribution with mean 1 and standard deviation \delta, given as an input parameter. Resample \alpha if \alpha \leq 0. If the ray passes through an endpoint of a wall, it is considered to have hit the wall. However, if the ray is parallel to a wall, it does not count as a hit.

After an operation, the wind causes the drone's velocity to change slightly from (v_x, v_y). Based on the input parameter \epsilon, two samples are drawn from a normal distribution with mean 0 and standard deviation \epsilon. After rounding these sampled values, they are denoted as (f_x, f_y). The new velocity of the drone then becomes (v_x + f_x, v_y + f_y).

At the end of each turn, the current position is updated to (x+v_x, y+v_y) based on the velocity (v_x, v_y) at that moment. However, if the line segment connecting (x, y) and (x+v_x, y+v_y) intersects with a wall (including cases where the line segment and the wall are parallel), it is considered a collision with the wall, and the position update is not performed; instead, the velocity is reset to (0, 0). It is guaranteed that the drone is not in contact with any wall in its initial state, and in the event of a collision, the drone returns to its position before the collision, ensuring that the drone does not begin moving while in contact with a wall.

If there is no collision with a wall, it is checked whether any destination has been reached. A destination (p_x, p_y), which has not yet been visited, is considered reached if the distance between the line segment connecting (x, y) and (x+v_x, y+v_y) and the destination point is 1000 or less. This distance is defined as the minimum distance between any point q on segment S and point p.

You can perform up to 5000 turns of operation, and the operation is completed immediately upon visiting all destinations.

Scoring

Starting with an initial score of 0, the score changes each turn as follows.

  1. Score is reduced by 2.
  2. If the drone hits a wall, the score is additionally reduced by 100. If it hits multiple walls at once, the score is only reduced by 100.
  3. If there is a destination reached for the first time, the score increases by 1000 for each one.

The score at the moment with the highest score up until either 5000 turns have elapsed or all destinations have been visited will be the score for the test case.

If your submission produces an illegal output or exceeds the time limit for some test cases, the submission itself will be judged as WA or TLE , and the score of the submission will be zero. The sum of the highest scores obtained during the contest will determine the final ranking, and there will be no system test after the contest. If more than one participant gets the same score, they will be ranked in the same place regardless of the submission time.

Input and Output

First, information is given from Standard Input in the following format.

N M \epsilon \delta
s_x s_y
p_{x,0} p_{y,0}
\vdots
p_{x,N-1} p_{y,N-1}
l_{x,0} l_{y,0} r_{x,0} r_{y,0}
\vdots
l_{x,M-1} l_{y,M-1} r_{x,M-1} r_{y,M-1}
  • The number of destinations is fixed at N=10 in all problems.
  • The number of walls M excluding the perimeter satisfies 0\leq M\leq 10.
  • (s_x,s_y) represents the initial position of the drone, satisfying -10^5< s_x,s_y< 10^5. It is guaranteed that it is not on a wall, including the outer perimeter.
  • (p_{x,i},p_{y,i}) denotes the coordinates of the i-th destination, satisfying -10^5\leq p_{x,i},p_{y,i}\leq 10^5. The destinations may be in contact with walls. For each destination, the distance to the initial position and/or other destinations is guaranteed to be at least 5000.
  • The (l_{x,i},l_{y,i}) and (r_{x,i},r_{y,i}) represent the coordinates of the i-th wall endpoint and satisfy -10^5\leq l_{x,i},l_{y,i},r_{x,i},r_{y,i}\leq 10^5. The wall has a positive length and is guaranteed to have no common part with any wall other than the perimeter. It is also guaranteed to have no more than one point in common with the outer perimeter. From these conditions, it is guaranteed that all points in the flight area are reachable without passing through the walls.

After reading the above information, repeat the following process for a maximum of 5000 turns.

For acceleration, output the acceleration vector (a_x,a_y) to Standard Output in the following format.

A a_x a_y

For measurements, output the direction (b_x,b_y) to be measured to Standard Output in the following format.

S b_x b_y

Only when performing a measurement, an integer value representing the measurement result is given in a single line from Standard Input.

The output must be followed by a new line, and you have to flush Standard Output. Otherwise, the submission might be judged as TLE. Note that the judge program will not respond to queries after all destinations have been visited nor after 5000 queries have been completed, so waiting for a response may result in a TLE.

At the end of the turn, information on the results of the drone's movement is given from Standard Input in the following format.

c h
q_0 \cdots q_{h-1}

The value c indicates whether or not it collided with a wall, with c=1 if it collided with a wall, and c=0 if it did not. No information about which wall it collided with is available. The value h represents the number of destinations visited for the first time this turn, and each q_i in the next line is the ID of the destination visited for the first time (0\leq q_i\leq N-1). If h=0, the line with q_i is skipped instead of a blank line.

Example

t Output Input
Prior information
2 0 10.0 0.1
43722 -75332
79243 32532
44002 -77034
0
A 150 -400
0 0
1
S 0 1
168969
0 1
1
\vdots

Input Generation

Let \mathrm{rand}(L,U) be a function that generates a uniform random integer between L and U, inclusive.

We describe the common parts of all the problems. Refer to the "Differences by Problem" section below for the parts specific to each problem.

Generation of s

Generate s_x=\mathrm{rand}(-99999,99999) and s_y=\mathrm{rand}(-99999,99999).

Generation of p_{x,i} p_{y,i}

For each i, generate p_{x,i}=\mathrm{rand}(-100000,100000) and p_{y,i}=\mathrm{rand}(-100000,100000). If there is a point in s or (p_{x,j}, p_{y,j}) with Euclidean distance less than 5000, we regenerate (p_{x,i},p_{y,i}).

Generation of walls

For each i, generate walls as follows.

First, generate l_{x,i}=\mathrm{rand}(-90000,90000) and l_{y,i}=\mathrm{rand}(-90000,90000), then set r_{x,i}'=l_{x,i}+\mathrm{rand}(-100000,100000) and r_{y,i}'=l_{y,i}+\mathrm{rand}(-100000,100000). If (l_{x,i},l_{y,i})=(r_{x,i}',r_{y,i}'), we regenerate the i-th wall. If r_{x,i}' is out of range (r_{x,i}'<-100000 or 100000<r_{x,i}') and r_{y,i}' is also out of range, we regenerate the i-th wall. Otherwise, set r_{x,i}=\min(100000,\max(-100000,r_{x,i}')) and r_{y,i}=\min(100000,\max(-100000,r_{y,i}')). If this wall (l_{x,i},l_{y,i})-(r_{x,i},r_{y,i}) has a shared point with another previously generated wall, or if the initial position (s_x,s_y) is on this wall, we regenerate the i-th wall. Otherwise, adopt it as the i-th wall.

Differences by Problem

Problem The number of test cases M \epsilon \delta
A 60 0 \mathrm{rand}(1,100) \mathrm{rand}(1,20)\times 0.01
B 60 10 \mathrm{rand}(0,1) 0.01
C 80 \mathrm{rand}(1,10) \mathrm{rand}(1,100) \mathrm{rand}(1,20)\times 0.01

Tools (Input Generator and Local Tester)

Please be aware that sharing visualization results or discussing solutions/ideas outside of the team during the contest is prohibited.

Specification of input/output files used by the tools

The input file given to the local tester contains random numbers \alpha and (f_x,f_y) in the following format at the end of the prior information.

\alpha_0
\vdots
\alpha_{4999}
f_{x,0} f_{y,0}
\vdots
f_{x,4999} f_{y,4999}

\alpha_t is the error in the measurement at turn t and (f_{x,t},f_{y,t}) is the change of velocity due to wind at turn t.

Your program may output comment lines starting with #. Since the judge program ignores all comment lines, you can submit a program that outputs comment lines as is. The local tester outputs the following comment line at the beginning of each turn in addition to the output of the solver program.

#p x y
#v v_x v_y

(x,y) and (v_x,v_y) are the coordinates and velocity of the drone at the start of this turn.