A - Problem C

Time Limit: 30 sec / Memory Limit: 1024 MB



問題概要

  • 問題のねらい: 1回目のコンテストと同様、本プログラミングコンテストは、買い物支援(配達)サービスの最適化をテーマとしている。本サービスを利用する顧客はそれぞれ異なる品物をお店に注文する(顧客からの注文には固有の\text{ID}が割り振られる)。お店が利用できる車は一台のため、配達中に注文された商品については、お店に戻ってその商品を車に積んでから、顧客のもとに商品を届けなければならない。
  • 得点: 最適化の目的は、制限時間 T_{\max} の間に「できるだけ多くの」商品を「できるだけ早く」顧客に届けることである。なお、注文は時刻 0 から時刻 0.95 \times T_{\max} の間に発生する可能性がある。
  • 諸制約: 本コンテストでは、車に積むことのできる商品の数に制限はない。ただし、ある注文に対応する商品をお店まで取りに行き、車に積めるのは、その商品が注文された以降の時刻に限る ことに注意せよ。
  • 問題 C: この問題においては、事前に注文に関する情報は与えられず、全ての注文は配達中にオンラインで発生する。但し、1回目のコンテストの問題Bとは異なり、この問題では以下のイベントが確率的に発生する。
  • New: イベント:
    • 渋滞: スピードウェイで渋滞が発生する可能性がある。
    • 車の故障: 配送に使う車が故障する可能性がある。
    • 注文のキャンセル: 顧客は注文してから時間が経過すると、注文をキャンセルする可能性がある。
    • 信号待ち: スピードウェイに入る、もしくはスピードウェイを横切る際、時刻に応じて信号待ちが発生する可能性がある(このイベントのみ時刻に応じて確定的)。

時間・空間について

  • 時間: t0 \leq t < T_{\max} を満たす整数であるとし、各 t において、あなたは時刻 t から t+1 にかけての行動を決定しなければならない。
  • 空間: 単純かつ無向であるグラフ G = (V, E) を考える。ここで V は頂点集合、E は辺集合である。車の移動・注文の発生はすべて、このグラフ内で起こるものとする。
  • 店および顧客の位置: それぞれの頂点 u \in V1 から |V| までで番号付けられている。頂点 u = 1 は店がある頂点であるとし、u = 2, \dots, |V| のうちスピードウェイを構成していない頂点は、顧客がいる頂点であるとする。
  • 道路: それぞれの辺 \left\{ u, v \right\} は、頂点 u と頂点 v を直接結ぶ道路であるとする。辺には整数距離が定められており、これを d_{u, v} \geq 1 と表記する。
  • New: グラフの生成方法: 地図を表すグラフは、下記アルゴリズムに基づいてランダムに生成される。注意:グラフ生成アルゴリズムは1回目のコンテストとは異なる。
グラフ G の生成アルゴリズム 本コンテスト(2回目のコンテスト)で用いられるグラフは下記性質を持つ。
  • グラフは 2 次元平面内の 25\times25 の頂点から生成される。
  • New: グラフ内には南北及び東西に伸びる 2 本のスピードウェイが存在する。スピードウェイ上の隣接頂点間の距離は 1 である。
  • New: グラフ内には、スピードウェイに加え、南北に伸びる線路が存在する。
  • New: スピードウェイと線路によりグラフは 6 つの領域に分割される。
  • 基本的に各頂点の注文頻度は 1 だが、一部の領域内の頂点の注文頻度は 2 である。スピードウェイを構成する頂点及び店舗に対応する頂点からは注文は発生しない(注文頻度 0)。
  • New: スピードウェイ以外の経路と比較して、スピードウェイでは平均 4 倍の速度で移動できる(つまり、距離が 1/4 である)。
overview

左図は生成初期ステージのグラフの一例であり、右図は生成された(最終的な)グラフの形状である。左図:頂点(灰色点)、スピードウェイ(黒点+黒線)、線路(破線)、6 つに分けられた領域(緑背景)。スピードウェイは隣接するスピードウェイ外の頂点と、(スピードウェイの交差点を基準として) 5 頂点おきにつながる。線路の東と西の領域の間も、線路とスピードウェイの交差点を基準として 5 頂点おきにつながる。右図:最終的なグラフ。頂点(ピンク及び緑色の点)、スピードウェイ以外の経路(細い灰色線)、スピードウェイ(太い灰色線)。スピードウェイ上にないピンクの点は注文頻度が 1 の頂点に対応し、緑色の点は注文頻度が 2 の頂点に対応する。

グラフ生成の疑似コード:
  • 入力:|V|, |E|, \mathrm{MaxDegree}=5(最大次数)
  • 頂点(店舗+顧客)の生成方法:
    • はじめに、R \leftarrow \lfloor \sqrt{|V|} \rfloorR を定める。ただし、本コンテストでは頂点数は |V| = R \times R を満たすことを前提としている。そうでない場合の処理など詳細はツールキットを参照のこと。
    • 次に、 (x, y) を以下の規則で 0 \leq x, y \lt R を満たす 2 次元座標平面上にプロットする。\forall u\in{1,...,|V|} に対して、
      • x \leftarrow (u-1) \mod R
      • y \leftarrow \frac{u-1-x}{R}
    • 最後に、頂点番号をランダムにシャッフルする。店舗に対応する頂点の番号は 1 である。
  • スピードウェイと線路
    • 南北に伸びるスピードウェイを構成する頂点を決定する。まず、一つの整数 x\in[R/2, 2R/3] を選ぶ。選ばれた x と同じ x 座標を持つ全ての頂点を(南北に伸びる)スピードウェイを構成する頂点に割り当てる。スピードウェイを構成する隣接頂点間の距離を 1 とする(図参照)。
    • 次に、東西に伸びるスピードウェイを構成する頂点を決める。 まず、一つの整数 y\in[R/3, 2R/3] を選ぶ。選ばれた y と同じ y 座標を持つ全ての頂点を(東西に伸びる)スピードウェイを構成する頂点に割り当てる。南北方向と同様に、スピードウェイを構成する隣接頂点間の距離を 1 とする(図参照)。
    • 2 本のスピードウェイに対して東西南北の 4 つの方向を割り当てる。
    • 最後に、線路は x=\xi+0.5 で定める。ただし、\xi\xi\in[R/6,R/3] を満たす整数で、一様ランダムに選択される(図参照)。
    • スピードウェイと線路によって、残りの頂点は 6 つの領域に分割される(図参照)。
    • スピードウェイは隣接するスピードウェイ外の頂点と、(スピードウェイの交差点を基準として) 5 頂点おきにつながる(図参照)。以下この辺を"スピードウェイの出入り口"と呼ぶ。
    • 線路の東と西の領域の間も、線路とスピードウェイの交差点を基準として 5 頂点おきにつながる(図参照)。
  • 最終的な頂点の位置の決定:
    • スピードウェイ、スピードウェイの出入り口、及び線路をまたぐ辺を作成の後、各頂点の位置をランダムなオフセット dx, dy \in [0, 1] を加えることによりずらす。最終的な頂点の位置は、(x + dx, y + dy)\in [0,R] \times [0,R] となる。
  • 6 つの領域内の道路網の作成方法:
    • 6 つの領域内の道路網を作成するため、頂点集合 u \in V に対して完全グラフ G_{\text{comp}} を作成する。次に各頂点ペア u, v \in V \times V に対して、辺の重み W_{u, v} を以下のように定める。:
      • スピードウェイを構成する異なる 2 頂点 u, v に対して、W_{u, v}\leftarrow 1 とする。
      • 同じ領域内に存在する 2 つの頂点のペア u, v に対して、W_{u, v}\leftarrow \mathrm{EuclideanDistance} とする。
      • 以前に作成した線路をまたぐ辺、及びスピードウェイの出入り口に関しても、2 頂点間のユークリッド距離を辺の重み W_{u, v} とする。
      • 最後に、残りの頂点ペアは全て W_{u, v}\leftarrow \infty とする。
    • 次に、既に割り当てられたスピードウェイ、スピードウェイの出入り口、及び線路をまたぐ辺を拡張する(含む)形で、 G_{\text{comp}} に対する 最小全域木 を作成する。最小全域木の |V|-1 本の辺は連結グラフを構成する。この処理で新たに加わった辺と、スピードウェイ、スピードウェイの出入り口、及び線路をまたぐ辺全てに対して、距離 d_{u,v}d_{u,v} \leftarrow \lceil 4 \times W_{u, v} \rceil で定める。
  • 残りの道路の作成方法:
    • 残りの |E|-(|V|-1) 本の道路は、次の手順で1本ずつ生成される。
      • \mathrm{cost}(u,v)を更新する。
      • グラフGの辺でつながっていないu, vのペアの内、\mathrm{cost(u,v)}の最小を与えるペアをつなぐ辺\left\{ u, v \right\}をグラフGに加える。
      • 選ばれた辺の距離 d_{u,v}d_{u,v} \leftarrow \lceil 4 \times W_{u, v} \rceil と定める。
    • ここで \mathrm{cost}(u,v) のベースは頂点間のユークリッド距離だが、低い次数の頂点が選ばれやすくなるように、また、できる限り道の交差を避けるため、斜め方向よりも縦横方向の道が選ばれやすくなるように \mathrm{cost}(u,v) を定める。以下に \mathrm{cost}(u,v) の計算方法の詳細を示す。
      • 各頂点 u\in V の次数 \mathrm{degree}(u) を計算する。次数 \mathrm{degree}(u)u\in V をいずれかの端点に含むグラフ G の辺の本数である。
      • 各頂点 u\in V の色を、頂点の初めの(ずらす前の)座標 (x,y) をもとに、下記のように定める。
        • x+y が偶数の場合 : \mathrm{color}(u) = 0
        • x+y が奇数の場合 : \mathrm{color}(u) = 1
      • ファクター f(u,v) を以下のように定める:
        • \mathrm{color}(u)\mathrm{color}(v) が同じ場合: \mathrm{f}(u,v) = 5
        • \mathrm{color}(u)\mathrm{color}(v) が異なる場合: \mathrm{f}(u,v) = 1
      • ファクター g(u) を以下のように定める:
        • \mathrm{degree}(u) \lt \mathrm{MaxDegree} の場合: g(u)=1
        • \mathrm{degree}(u) \geq \mathrm{MaxDegree} の場合: g(u)=\infty
      • \mathrm{cost}(u,v) を以下のように計算する。:
        • \mathrm{cost}(u,v) = W_{u,v}\times \mathrm{degree}(u) \times \mathrm{degree}(v) \times f(u,v) \times g(u) \times g(v).
  • 各顧客の注文頻度の決定方法:
    • まず、各頂点 u \in V に注文頻度 f_u \in \left\{0,1,2\right\} を割り当てる。
    • 店舗の注文頻度を0に初期化する: f_1 \leftarrow 0.
    • その他の注文頻度を1に初期化する: f_u \leftarrow 1
    • 以下、注文頻度2の頂点を決める。そのためにまず、座標平面上の [R/4,3R/4]\times[R/4,3R/4] の領域内に一様ランダムに1点、中心点 c=(c_x,c_y) をプロットする(c=(c_x,c_y)\in [R/4,3R/4]\times[R/4,3R/4])。次に頂点 u=2,...,|V| に対して以下の処理を行う:
      • \mathrm{EuclideanDistance}(c,u)\le R/8 + \mathrm{uniformRandom}[0,R/8] の場合、 f_{u} \leftarrow 2 とする。
    • 最後に、スピードウェイを構成する全ての頂点の注文頻度を f_u \leftarrow 0 とする。

車の位置と移動について

配達には車を利用する必要がある。車の位置は次に示すように二種類に分類される。

  • 車の位置: 以下の二種類に分類される。
    • 頂点 u \in V 上にいる場合
    • \left\{ u, v \right\} 上にいる場合。より具体的に言えば、u から v の方向に x (0 < x < d_{u, v}) だけ離れている場合である

また、毎時刻 t において、あなたは以下に示すとおりに車を操作できる。

  • 車の移動: あなたが取れる行動は以下の二種類である。

    • stay: 移動せずその場にとどまる
    • move w: w \in V の方向に向かって距離 1 だけ進む

    move w を選択するとき、w は以下の条件を満たさなければならない。これらの条件を満たさない場合はジャッジ側から NG が通知されることに注意せよ。

    • ww \in V を満たす頂点である
    • 車が頂点 u \in V 上にいる場合、頂点対 \left\{ u, w \right\} がグラフの辺集合に含まれていなければならない。すなわち、\left\{ u, w \right\} \in E でなければならない
    • 車が辺 \left\{ u, v \right\} 上にいる場合、w = u または w = v でなければならない

  • New: 渋滞発生中にスピードウェイにいる場合、または赤信号期間中にスピードウェイに入る/横切る場合、車は所望の方向に動けない場合がある。詳細は下記"渋滞"や"信号待ち"を参照のこと。

注文・配達等について

  • 注文: それぞれの注文は「注文 ID」「配達先 v \in V」「注文が発生した時刻 t」の三種類の情報を持つ。詳しくは、後述の入力フォーマットを参照のこと。
  • 注文発生について: 顧客からの新しい注文は、0 \leq t \leq T_{\mathrm{last}} = 0.95 \times T_{\max} を満たす時刻 t において確率 p_{\mathrm{order}}(t) で発生する。それぞれの頂点には注文頻度 f_i が定められており、注文が発生するときにその配送先が頂点 i となる確率は \frac{f_i}{\sum_{k} f_k} である。詳しくは以下の疑似コードまたはサンプルコードを参考のこと。

注文発生について
  • 入力: 注文が発生しうる時刻の最大値 T_{\mathrm{last}} と、時刻ごとの注文発生確率を表す関数 p_{\mathrm{order}}(t).
  • 初期化: \mathrm{ID} \leftarrow 0
  • 各時間ステップ t = 0, ..., T_{\mathrm{last}} で以下を実行する:
    • 実数 r \in \left[ 0,1 \right] を一様ランダムに生成する
    • r \le p_{\mathrm{order}}(t) の場合:
      • 1つの頂点 u (u \in V, u \neq 1) を、それぞれの頂点に割り当てられた頻度 f_{u} で重み付けをしてランダムに選択する
      • \mathrm{ID} \leftarrow \mathrm{ID} + 1
      • 注文を発生させる。ここで注文は(注文ID, 注文時間 t, (お届け先の)頂点番号 u \in V)を含む。
    • 上記以外 ( r \gt p_{\mathrm{order}}(t)) の場合: 注文は発生しない
  • 時刻ごとの注文発生確率を表す関数 p_{\mathrm{order}}(t) を下記のように定める:
  • p_{\text{order}}(t) = \begin{cases} t / T_{\text{peak}}, & \text{if } 0\le t \lt T_{\text{peak}}, \\ (T_{\text{last}} - t) / (T_{\text{last}}- T_{\text{peak}}), & \text{if } T_{\text{peak}} \le t \lt T_{\text{last}}, \\ 0, & \text{if } T_{\text{last}} \le t, \end{cases}
  • ここで T_{\text{last}}:=0.95 \times T_{\max} であり、 T_{\text{peak}} は区間 [0, T_{\text{last}}] から一様ランダムに定める
  • 注意: T_{\text{peak}} の値は、入力では与えられない。

  • 配達: 注文を受けて、それに対応する商品を顧客まで配達するためには、注文が発生した後に次に示す手順を踏む必要がある。
    1. 車を店まで移動させる: 車が店まで到達すると、現在時刻を同じかそれより前に発生した注文について、それに対応する商品をすべて車に積むことができる。将来にやってくる注文に関しては、商品を車に積むことができないことに注意せよ。
    2. 車を顧客がいる場所まで移動させる: 配達を完了させるためには、顧客がいる頂点まで車を移動させる必要がある。ここで、その顧客の注文に対応する商品が車に積まれていない場合は、たとえ顧客がいる頂点まで車を移動させたとしても配達が完了しないことに注意せよ。
  • 注意すべき制約: 注文 ID は注文を識別するためのものであり、互いに異なる整数が割り当てられる。また、一度に車に積むことのできる商品の数には上限がないことに注意されたい。

  • New: 注文は時間が経過するとキャンセルされる可能性がある。詳細は下記"注文のキャンセル"を参照のこと。

New: イベント

この問題では、以下のイベントが確率的に発生する(但し信号待ちは時刻により確定的なイベント)。

  • 渋滞: 渋滞はスピードウェイの異なる4方向ごと独立に発生する。渋滞が発生したスピードウェイ上に車が居る場合、車は渋滞方向に 1/10 の確率でしか進めない(90\% の確率で動けない)。詳しくは以下の疑似コードまたは配布するツールキットを参考のこと。

    疑似コード: 渋滞
    • 入力1: p_{\text{duration}}(t) // 渋滞継続期間を生成する確率分布
    • 入力2: p_{\text{delay}}(t) // 渋滞開始時刻(目安時刻からのオフセット)を生成する確率分布
    • 入力3: p_{\text{jam}}=0.25 // 渋滞発生確率
    • 入力4: p_{\text{move}}=0.1 // 車が渋滞方向に進める確率

      // 渋滞タイミング決定のための前処理
    • スピードウェイの4方向 d=1,2,3,4 それぞれに対して、4つの渋滞開始時刻の目安 t_{d,i} (i=1,2,3,4) を一様ランダムにサンプリングする:
      • t_{d,i} \sim \mathrm{uniformRandom}[0,T_{\max})
      • \forall d : t_{d,1} \le t_{d,2} \le t_{d,3} \le t_{d,4}
    • それぞれの時刻 t_{d,i} を基準として、スピードウェイの d の方向に p_{\text{jam}} の確率で渋滞が発生する。実装上は、渋滞発生有無及び渋滞時間を以下の方法で予め決定する:
      • 16(d,i) (d = 1,...,4) & (i = 1, ..., 4) に対して以下の処理を行う:
        • \mathrm{uniformRandom}[0,1] \le p_{\text{jam}} の場合: // 渋滞発生
          • \delta_{d,i} をサンプリングする: \delta_{d,i} \sim p_{\text{delay}}(t)
          • d 方向の渋滞開始時刻 t_{\text{start}, d, i} を決定する: t_{\text{start}, d, i} \leftarrow t_{d,i} + \delta_{d,i}
          • 渋滞継続期間 \Delta_{\text{jam}, d, i} をサンプリングする: \Delta_{\text{jam}, d, i} \sim p_{\text{duration}}(t)
          • d 方向の渋滞終了時刻 t_{\text{end}, d, i} を決定する: t_{\text{end}, d, i} \leftarrow t_{\text{start}, d, i} + \Delta_{\text{jam}, d, i}
        • その他の場合: // 渋滞は発生しない
    • それぞれの方向 d = 1,...,4[t_{\text{start}, d, i}, t_{\text{end}, d, i}] を集計する。ここで、4つの渋滞期間(i = 1, ..., 4)のいずれかがオーバーラップする場合、期間はまとめられる
    • コンテスタントのプログラムは、全 16 つの時刻 t_{d,i} を入力として受け取る。但し、渋滞発生期間 [t_{\text{start}, d, i}, t_{\text{end}, d, i}] はコンテスタントには通知されない

      // 注文発生中の処理
    • 各時間ステップ t=0,..., T_{\max}-1 で以下を実行する:
        // コンテスタントに渋滞を通知する
      • 各方向 d=1,2,3,4 に対して以下を実行する:
        • t\in [t_{\text{start}, d, i}, t_{\text{end}, d, i}] の場合:
          • コンテスタントに \mathrm{jam}_d=1 を通知する // 渋滞中
        • その他の場合:
          • コンテスタントに \mathrm{jam}_d=0 を通知する // 渋滞無し
        // 車の移動に対する処理
      • 車の移動が条件を満たしているか否か、通常通り判定する(詳細は"車の移動"を参照のこと)
      • 渋滞が発生していない場合、車は通常通り行動する
      • 渋滞が発生しており、且つ3つの条件 (1.車がスピードウェイ上に居る)、(2. d の方向に動いている)、(3. d の方向に渋滞が発生している)が同時に満たされている場合:
        • \mathrm{randomUniform}[0,1] \le p_{\text{move}} の場合:
          • 車を d の方向に進める。コンテスタントに OK を通知する
        • その他の場合:
          • 車はその場にとどまる。コンテスタントに JAM を通知する

    • p_{\text{duration}}(t) は平均値 \mu=1000 の指数分布である。詳細は下記"確率分布"もしくは配布するツールキットを参照のこと
    • p_{\text{delay}}(t)\mathrm{median}=100, \epsilon=3 のべき分布である。詳細は下記"確率分布"もしくは配布するツールキットを参照のこと 

  • 車の故障: 配送に使う車は途中で故障する可能性がある。但し、予め故障が発生する前に、コンテスタントは WARNING t の通知を受け取る。この通知を受けてから t ステップ以内に店に戻れば、車は修理される。もし、 t ステップ以内に店に戻らなければ、コンテスタントには BROKEN と通知され、その通知から 300 ステップの間、車を動かすことができない。詳しくは以下の疑似コードまたは配布するツールキットを参考のこと。

    疑似コード: 車の故障
    • 入力: 車の正常運転期間を生成する確率分布 p_{\text{car ok}}(t)
    • 入力: 車の故障警告期間 T_{\text{warning}}
    • 初期化: t_{\text{car}} に車の正常運転期間を設定し (t_{\text{car}} \sim p_{\text{car ok}}(t))、車の状態を0(正常)にする(\mathrm{carStatus} = 0)
    • 各時間ステップ t=0,..., T_{\max}-1 で以下を実行する:
        // 車の状態の切り替え
      • if \mathrm{carStatus} == 0 and t_{\text{car}} == 0: // 車の故障警告状態へ遷移
        • t_{\text{car}} \leftarrow T_{\text{warning}}
        • \mathrm{carStatus} \leftarrow 1 // 故障警告状態
      • if \mathrm{carStatus} == 1 and t_{\text{car}} == 0: // 車の故障状態へ遷移
        • t_{\text{car}} \leftarrow 300
        • \mathrm{carStatus} \leftarrow 2 // 故障状態
      • if (\mathrm{carStatus} == 1 and (車が店に居る)) or (\mathrm{carStatus} == 2 and t_{\text{car}} == 0:) // 車が修理される
        • t_{\text{car}} \leftarrow p_{\text{car ok}}(t)
        • \mathrm{carStatus} \leftarrow 0 // 車は正常状態
      • // コンテスタントに車の状態を通知
      • if \mathrm{carStatus} == 0: NOT_BROKEN を通知
      • if \mathrm{carStatus} == 1: WARNING t を通知 // t = t_{\text{car}}
      • if \mathrm{carStatus} == 2: BROKEN を通知
      • // コンテスタントから車の行動を受け取る
      • \mathrm{move} \leftarrow コンテスタントの出力
      • // 車の行動を処理する
      • if \mathrm{carStatus} \in \{0,1\} : 通常通り判定
      • if (\mathrm{carStatus} == 2 and \mathrm{move} is not -1:)
        • NG を通知 // 故障中は -1 (stay) を出力しなければならない
      • // t_{\text{car}}1 減らす
      • t_{\text{car}} \leftarrow t_{\text{car}} - 1
    • 注意1: p_{\text{car ok}}(t) は、\mathrm{median} = \frac{1}{T_{\max}}, \epsilon = 2.5 のべき分布から生成される乱数の逆数を生成する分布である。詳細は下記"確率分布"もしくは配布するツールキットを参照のこと
    • 注意2: 車の状態が正常の場合 (\mathrm{carStatus} == 0)、 t_{\text{car}} はコンテスタントには通知されない
    • 注意3: 車が故障中の場合 (\mathrm{carStatus}==2)、コンテスタントのコードは -1 (stay) を出力しなければならない。-1 を出力しない場合、WA (不正解)となる

  • 注文のキャンセル: 注文してから T_{\text{wait}}=2000 ステップ以上配達が完了しない場合、顧客はその注文をキャンセルする可能性がある。注文のキャンセルタイミングは確率的に決定される。詳しくは以下の疑似コードまたは配布するツールキットを参考のこと。

    疑似コード: 注文のキャンセル
    • 入力: 固定待ち時間 T_{\text{wait}}=2000 と、追加待ち時間 t_{\text{extra}} を生成する確率分布 p_{\text{extra}}(t)
    • 各時間ステップ t=0,..., T_{\max}-1 で以下を実行する:
        // 注文発生時に注文キャンセル時間 t_{\text{cancel}}(\text{ID}) を決定する:
        • 追加待ち時間 t_{\text{extra}} をサンプリングする: t_{\text{extra}} \sim p_{\text{extra}}(t)
        • t_{\text{cancel}}(\text{ID}) \leftarrow t + T_{\text{wait}} + t_{\text{extra}}
        // 注文キャンセルの判定を行う:
        • 未配達の各注文に対して以下の処理を行う:
          • t_{\text{cancel}}(\text{ID}) < t の場合、注文キャンセル通知を出力する

    • 注意1: t_{\text{extra}}t_{\text{cancel}}(\text{ID}) は、コンテスタントには通知されない
    • 注意2: p_{\text{extra}}(t) は、\mathrm{median} = \frac{1}{T_{\max}}, \epsilon = 0.5 のべき分布から生成される乱数の逆数を生成する分布である。詳細は下記"確率分布"もしくは配布するツールキットを参照のこと

  • 信号待ち: スピードウェイに入る、もしくはスピードウェイを横切る際、信号待ちが発生する可能性がある。正確に言うと、信号待ちが発生するのは、車がスピードウェイを構成しない頂点から移動し、スピードウェイを構成する頂点に到達したときである(つまり、車が既にスピードウェイ上を走っている場合は信号待ちは発生しない)。信号待ちが発生するか否かは時刻 t に応じて変化する。詳しくは以下の疑似コードまたは配布するツールキットを参考のこと。

    疑似コード: 信号待ち
    • 入力: 信号の周期 P_{\text{light}}
    • 各時間ステップ t=0,..., T_{\max}-1 で以下を実行する:
      • 車がスピードウェイを構成しない頂点から移動し、スピードウェイを構成する頂点に到達した場合、もしくは前時間ステップで WAIT x の通知を受け取っている場合:
        • if (\lfloor t / P_{\text{light}} \rfloor \mod 2) == 0: // 青信号
          • コンテスタントは OK の通知を受け取る
          • 車はスピードウェイを構成する頂点に移動する
          • 次の時間ステップの車の行動は通常通り処理される
        • else: // 赤信号
          • x \leftarrow P_{\text{light}} - \left(t \mod P_{\text{light}}\right)
          • コンテスタントは WAIT x の通知を受け取る
          • 車はスピードウェイを構成する頂点に移動する
          • 車は次の x 時間ステップの間、現在の(スピードウェイを構成する)頂点に留まらなくてはならない
    • 注意: このイベントのみ他のイベントと異なり、時刻に応じて確定的である。

  • 確率分布: イベントで用いられる確率分布の定義を以下に示す。より詳細に関しては、配布するツールキットを参照のこと

    定義: 確率分布
    • 本コンテストでは、次の 3 タイプの乱数が用いられる:
      (i) 指数分布から生成される乱数、(ii) べき分布から生成される乱数、(iii) べき分布から生成される乱数の逆数
    • べき分布はロングテールを持つため、(ii)の乱数は多くの(値の大きな)外れ値が生じうる。同様の理由で(iii)の乱数は多くの(値の小さな)外れ値が生じうる。
    • 乱数の値域(確率分布の定義域)は、t \in [0,\infty) である。
    • 指数分布
      • パラメータ: \mu (平均値)
      • 確率分布関数: p(t) = \frac{1}{\mu}\exp{\left(-\frac{t}{\mu}\right)}
      • 上側確率: P(t \ge s) := \int_{s}^{\infty} p(t) dt = \exp{\left(-\frac{s}{\mu}\right)}
      • 渋滞継続期間は、このタイプの分布から生成される。
    • べき分布
      • パラメータ: \epsilon (指数)と \mathrm{median} (中央値)
      • スケーリングパラメータ: \mu = \frac{\mathrm{median}}{2^{\frac{1}{\epsilon}} - 1}
      • 確率分布関数: p(t)= \frac{\epsilon}{\mu}\left(1+\frac{t}{\mu}\right)^{-(1+\epsilon)}
      • 上側確率: P(t \ge s) := \int_{s}^{\infty} p(t) dt = \left(1+\frac{s}{\mu}\right)^{-\epsilon}
      • 渋滞開始時刻(目安時刻からのオフセット)は、このタイプの分布から生成される。
    • べき分布から生成される乱数の逆数
      • パラメータ: \epsilon, \mathrm{median}
      • 乱数 x:=1/t がべき分布 p(x) (パラメータ \epsilon, \mathrm{median}) から生成される。
      • 実装上は、まずべき分布 p(x) (パラメータ \epsilon, \mathrm{median}) から x をサンプリングし、その逆数を乱数 t \leftarrow 1/x としている。
      • 故障イベントの際の車の正常運転期間と、注文のキャンセルの際の追加待ち時間は、このタイプの分布から生成される。

採点方法

  • 各テストケースの得点の合計がその解答プログラムの得点となる。コンテスト中には 30 個のテストケースが存在する。
  • コンテスト終了後に 100 個の(コンテスト中とは異なる)テストケースに対してシステムテストを行い、その得点を最終得点とする。
  • 各テストケースについて、以下のように得点(Score)を計算する。

    \text{Score} = \sum_{i \in D} {(T_{\max})}^{2} - {(\mathrm{waitingTime}_i)}^{2},

    ここで、
    • D は、時刻 t=T_{\max} までに配達を完了した注文の集合である。
    • i 番目の注文の待ち時間: \mathrm{waitingTime}_i = \mathrm{deliveredTime}_i - \mathrm{orderedTime}_i.
    • WA(不正解)となったテストケースが存在した場合、そのケースの得点は 0 点になる。

問題文 C

問題Cはインタラクティブな問題である。 この問題において、時刻 t=0,...,T_{\text{last}}-1 で発生する顧客からの注文は、時刻 t におけるコンテスタント側の行動を決定する 直前に 与えられる。 また、コンテスト側のアルゴリズムは確率的に発生するイベント(渋滞、車の故障、注文のキャンセル、信号待ち)に対応しなければならない。 より具体的には、コンテスタント側とジャッジ側が以下で示す流れに沿って処理を行う。

コンテスタント ジャッジ
グラフ G を出力
New: 渋滞開始時刻の目安 t_{d,i} を出力
+ New:時刻 t における車の状態を通知
+ New:時刻 t における渋滞の状況を通知
+ New:時刻 t で新たにキャンセルされた注文を出力
+ 時刻 t で新たに発生した注文情報を出力
+ 時刻 t で新たに車に積まれた商品に対応する注文情報を出力
+ 時刻 t における行動を決定して出力
+ その行動及びイベントの発生状況(渋滞、信号待ちなど)を判定し、OKNGJAMWAIT tのいずれかを出力 (詳細は下の"入出力形式2"を参照)
+ 時刻 t+1 で配達が完了した注文情報を出力

ジャッジによるグラフ、注文発生頻度、及びイベントに関する設定値は、はじめに一回だけ出力される。表の左に "+" が書かれている処理は繰り返し処理であり、0 \leq t \lt T_{\max} を満たす整数 t において、表で示した順番通りに毎回行われる。


入出力形式1

はじめに、ジャッジ側からグラフ G 、各頂点の注文発生頻度 f_i 、渋滞開始目安時刻 t_{d,i} 、信号待ちの周期 P_{\text{light}} 、故障警告期間 T_{\text{warning}} 、時間ステップの最大値 T_{\max} が以下の形式で標準入力に与えられる。

|V| |E|
u_1 v_1 d_{u_1, v_1} e_{u_1, v_1} e_{v_1, u_1}
u_2 v_2 d_{u_2, v_2} e_{u_2, v_2} e_{v_2, u_2}
\vdots
u_{|E|} v_{|E|} d_{u_{|E|}, v_{|E|}} e_{u_{|E|}, v_{|E|}} e_{v_{|E|}, u_{|E|}}
f_1 f_2 \ldots f_{|V|}
t_{1,1}, \cdots, t_{1,4}
\vdots
t_{4,1}, \cdots, t_{4,4}
P_{\text{light}}
T_{\text{warning}}
T_{\max}
  • 1 行目の |V| はグラフの頂点数、|E| はグラフの辺数を表す。
  • 続く |E| 行で、グラフの辺が与えられる。|E| 行のうち i 行目は、頂点 u_iv_i の間の辺に対応する。d_{u_i, v_i} は距離を表し、 e_{u_i, v_i}e_{v_i, u_i} はそれぞれ u_i \to v_iv_i \to u_i 方向の辺のタイプを表す。ここで辺のタイプとは、
    • e_{u_i, v_i} = 0 : u_i \to v_i 方向の辺は通常の道であることを表す。
    • e_{u_i, v_i} = d \in {1,2,3,4} : u_i \to v_i 方向の辺は d 方向のスピードウェイであることを表す。
    • e_{u_i, v_i} = 5 : u_i \to v_i 方向の辺において、頂点 v_i がスピードウェイ上の頂点であることを表す。(頂点 u_i はスピードウェイ上の頂点ではない)
    • e_{u_i, v_i} = 6 : u_i \to v_i 方向の辺において、頂点 u_i がスピードウェイ上の頂点であることを表す。(頂点 v_i はスピードウェイ上の頂点ではない)
  • 続く 1 行で、それぞれの頂点において注文が発生する頻度が与えられる。i 番目に与えられる整数は、頂点 i に新たな注文が発生する相対頻度が f_i であることを表す。
  • 続く 4 行の各行 t_{d,1}, \cdots, t_{d,4} (d=1,\cdots,4) は、それぞれ方向 d のスピードウェイにおける渋滞開始時刻の目安を表す。
  • 続く 1 行で、信号待ちの周期 P_{\text{light}} が与えられる。
  • 続く 1 行で、車の故障警告期間 T_{\text{warning}} が与えられる。
  • 最後の 1 行で、コンテスタント側とジャッジ側が互いに処理を行う時間ステップの最大値 T_{\max} が与えられる。

入出力形式2

各時刻 t に以下の情報が標準入力に与えられる。

\mathrm{CAR\_STATUS}
\mathrm{jam}_{1} \mathrm{jam}_{2} \mathrm{jam}_{3} \mathrm{jam}_{4}
N_{\text{cancel}}
\mathrm{cancel\_id}_1
\mathrm{cancel\_id}_2
\vdots
\mathrm{cancel\_id}_{N_{\text{cancel}}}
N_{\text{new}}
\mathrm{new\_id}_1 \mathrm{dst}_1
\mathrm{new\_id}_2 \mathrm{dst}_2
\vdots
\mathrm{new\_id}_{N_{\text{new}}} \mathrm{dst}_{N_{\text{new}}}
N_{\text{put}}
\mathrm{put\_id}_1
\mathrm{put\_id}_2
\vdots
\mathrm{put\_id}_{N_{\text{put}}}
  • 最初の行は、車の状態を表す:
    • NOT_BROKEN : 正常状態
    • WARNING t : 故障警告状態。店に戻らなければ t ステップ後に故障する状態である。
    • BROKEN : 故障状態。コンテスタントは stay 、つまり -1 を出力しなければならない。それ以外の出力では NG となる。
  • 2 行目は、スピードウェイの各方向 d=1,2,3,4 の渋滞状況を表す。\mathrm{jam}_d: 0 であれば渋滞は発生しておらず、\mathrm{jam}_d: 1 であれば渋滞発生中である。
  • 続く 1 行の N_{\text{cancel}} は、その時刻において新たにキャンセルされた注文の数を表す。
  • 続く N_{\text{cancel}} 行でキャンセルされた注文が与えられる。i 行目はオーダーID \mathrm{cancel\_{id}}_i に対応する注文がキャンセルされたことを表す。
  • 続く 1 行の N_{\text{new}} は、その時刻において新たに発生した注文の数を表す。
  • 続く N_{\text{new}} 行で、新たに発生した注文情報が与えられる。i 行目の注文情報は、注文 ID が \mathrm{new\_id}_i であり、その注文の発生元 (お届け先) が頂点 \mathrm{dst}_i であることを表す。
  • 続く 1 行の N_{\text{put}} は、その時刻において店舗で新たに車に積まれた商品の数を表す。
    • その時点で車が店舗にいなければ、N_{\text{put}}0 である。
  • 続く N_{\text{put}} 行で、新たに車に積まれた商品に対応する注文情報が与えられる。i 行目の注文情報は、車に積まれた商品に対応する注文 ID が \mathrm{put\_id}_i であることを表す。

次に、コンテスタントは、時刻 t (0 \leq t \lt T_{\max}) における行動 \mathrm{command} を標準出力に出力しなければならない。

\mathrm{command}

ここで、\mathrm{command} は以下の形式でなければならない。

  • stay を行う場合: -11 行で出力
  • move w を行う場合: w1 行で出力

ただし、move w の場合、w は以下の条件を全て満たす必要がある。条件に違反している場合、ジャッジ側は NG を出力する。その場合、コンテスタントはプログラムを即座に終了させなければならない。即座に終了させた場合は WA (不正解) となることが保証されるが、そうでない場合の動作は未定義である。

  • w1 \leq w \leq |V| を満たす整数である
  • 車が頂点 u 上にいる場合、\left\{ u, w \right\} \in E が成り立つ
  • 車が辺 \left\{ u, v \right\} 上にいる場合、w = u または w = v が成り立つ

また、車の状態が BROKEN の場合は、コンテスタントコードは stay 、つまり -1 を出力しなければならない。それ以外の出力では NG となる。 NG が出力された場合、コンテスタントはプログラムを即座に終了させなければならない。即座に終了させた場合は WA (不正解) となることが保証されるが、そうでない場合の動作は未定義である。 時刻 t における行動が出力された直後に、ジャッジ側から時刻 t+1 に関する以下の情報が標準入力に与えられる。

\mathrm{verdict}
N_{\text{achieve}}
\mathrm{achieve\_id}_1
\mathrm{achieve\_id}_2
\vdots
\mathrm{achieve\_id}_{N_{\text{achieve}}}
  • \mathrm{verdict} は、時刻 t における車の行動が実行可能であるかを表す文字列であり、以下の 4 種類のいずれかである。

    • OK: 行動は実行可能であり、車は行動に従って動く(もしくはとどまる)ことを表す。
    • NG: 行動は実行不可能であり、NG が出力された場合、コンテスタントはプログラムを即座に終了させなければならない。即座に終了させた場合は WA (不正解) となることが保証されるが、そうでない場合の動作は未定義である。
    • JAM: 渋滞によって車が進めなかったことを表す。(渋滞方向への移動であっても、車が進めれば OK が出力される)
    • WAIT t: 行動は実行可能であり、車が所望の頂点に移動したことを表す。ただし、赤信号のため次の t ステップの間、その場にとどまらなくてはならない。その間、コンテスタントコードは -1 を出力しなければならない。 -1 を出力しなければ NG となる。なお、信号待ちに該当する頂点に移動した場合であっても、青信号であれば OK が出力される。
  • N_{\text{achieve}} は、その時刻において配達が完了した注文の数を表す。

    • その時点で車が店にいなければ、N_{\text{achieve}}0 である。
  • 続く N_{\text{achieve}} 行で、配達が完了した注文情報が与えられる。i 行目の注文情報は、注文 ID が \mathrm{achieve\_id}_i であることを表す。

また、T_{\max} 回目の行動に対するジャッジからの入力を受け取ったあと、あなたは プログラムを即座に終了させなければならない。

入出力制約

  • 入力で与えられる数値はすべて整数である
  • 出力はすべて整数でなければならない

初期化

  • T_{\text{max}} = 10000
  • |V| = 625
  • 1.5 |V| \leq |E| \leq 2|V|
  • 1 \leq u_{i}, v_{i} \leq |V| (1 \leq i \leq |E|)
  • 1 \leq d_{u_i, v_i} \leq \lceil 4\sqrt{2|V|} \rceil (1 \leq i \leq |E|)
  • 0 \leq e_{u_i, v_i}, e_{v_i, u_i} \leq 6 (1 \leq i \leq |E|)
  • 与えられるグラフは自己ループ・多重辺が存在せず、連結であることが保証される
  • f_1 = 0
  • f_i \in \left\{0, 1, 2 \right\} (2 \leq i \leq |V|)
  • 0 \leq t_{d,1} \leq t_{d,2} \leq t_{d,3} \leq t_{d,4} \lt T_{\text{max}} (1 \leq d \leq 4)
  • 50 \leq T_{\text{warning}} \leq 120
  • 10 \leq P_{\text{light}} \leq 30

繰り返し処理

  • \mathrm{CAR\_STATUS} \in \{ NOT_BROKEN, WARNING t, BROKEN\}
  • \mathrm{jam}_{1}, \mathrm{jam}_{2}, \mathrm{jam}_{3}, \mathrm{jam}_{4} \in \{0,1\}
  • 0 \leq N_{\text{new}} \leq 1
  • 1 \leq \mathrm{new\_id}_{i} \leq T_{\text{last}}+1 (1 \leq i \leq N_{\text{new}}).
    注意: 上で説明されたルールに従って注文が生成されたとき、発生する注文の件数の最大値は T_{\text{last}} + 1 となる。ゆえに、\mathrm{new\_id}_{i} の取りうる値は 1 から T_{\text{last}} + 1 までの整数である。
  • ジャッジからの出力全体を通して、注文ID \mathrm{new\_{id}}_i はそれぞれ相異なる整数である
  • 2 \leq \mathrm{dst}_i \leq |V| (1 \leq i \leq N_{\text{new}})
  • 0 \leq N_{\text{cancel}} \leq T_{\text{last}}+1
  • 1 \leq \mathrm{cancel\_id}_{i} \leq T_{\text{last}}+1 (1 \leq i \leq N_{\text{cancel}}).
  • 0 \leq N_{\text{put}} \leq T_{\text{last}}+1
  • 1 \leq \mathrm{put\_id}_{i} \leq T_{\text{last}}+1 (1 \leq i \leq N_{\text{put}}).
  • 時刻 t におけるあなたの行動を表す整数は -1 または 1 \leq w \leq |V| を満たす整数 w でなければならない
  • \mathrm{verdict} \in \{OK, NG,JAM, WAIT t\}
  • 0 \leq N_{\text{achieve}} \leq T_{\text{last}}+1
  • 1 \leq \mathrm{achieve\_id}_{i} \leq T_{\text{last}}+1 (1 \leq i \leq N_{\text{achieve}}).

入出力例

以下では入出力例を用いて、コンテスタント側とジャッジ側の挙動を説明する。

  • グラフ : 以下では 16 頂点、 18 つの辺をもつグラフを例として挙げる。
  • スピードウェイ: 下図の黒い頂点で表す。以下のように 4 つの方向がある。
    • d=1 : 3\to7\to11\to15
    • d=2 : 15\to11\to7\to3
    • d=3 : 9\to10\to11\to12
    • d=4 : 12\to11\to10\to9.
  • 時間ステップ 0 から 8 : 車は頂点 14 を訪問し、注文(ID: 1) の配達を行う。この間、頂点 16 で発生した注文がキャンセルされる。配達経路を赤い矢印で示す。渋滞によりステップ 4 から 5 の間、車は動けない。
  • 時間ステップ 8 から 14 : 車の故障警告 WARNING 5 が発生し、修理のため車は店(頂点 1 )を目指す。しかし、頂点 9 で信号待ち( WAIT 2 )が発生し、ステップ 11, 12 で車は動けない。
  • 時間ステップ 13 で頂点 1, 9 の間で車が故障し、BROKEN の通知を受け取る。
  • 時間ステップ 14 :車の故障中に実行不可能な行動を行ったため、NG が出力される。
overview

注意: この例はわかりやすさのために作られたものであり、制約条件は満たさない。

時間 コンテスタント ジャッジ 説明
16 18
5 1 2 0 0
2 3 2 5 6
2 6 4 0 0
3 4 2 6 5
3 7 1 1 2
4 8 4 0 0
1 6 2 0 0
1 9 2 5 6
7 11 1 1 2
9 10 1 3 4
9 13 2 6 5
9 14 2 6 5
10 11 1 3 4
11 12 1 3 4
11 15 1 1 2
12 16 2 6 5
14 15 2 5 6
15 16 2 6 5
0 1 0 1 1 2 0 1 0 0 0 0 1 1 0 1
3 167 311 913
63 617 791 837
325 473 893 915
156 387 627 849
6
5
10000
はじめに、ジャッジ側からデータが与えられる
1 行目: グラフは |V| = 16 個の頂点と |E| = 18 つの辺から構成される
次の 18 行 (行 2 - 19) は、グラフの辺に関する情報を表す。例えば、
2 行目: 頂点 5 と頂点 1 の間の距離が 2 で、4 番目の数字 0 は、5\to 1 方向の道が通常の道であることを示し、最後の 01\to 5 方向の道も通常の道であることを示す
3 行目: 頂点 2 と頂点 3 の間の距離が 2 で、4 番目の数字 5 は、2\to 3 の方向に進むと通常の道からスピードウェイに入ることを示し、最後の 63\to 2 方向に進むとスピードウェイから通常の道に戻ることを示す
6 行目: 頂点 3 と頂点 7 の間の距離が 1 で、4 番目の数字 1 は、3\to 7 の方向がスピードウェイの方向 d=1 に対応することを示し、最後の 27\to 3 の方向がスピードウェイの方向 d=2 に対応することを示す
20 行目: 各頂点における注文発生頻度を示す
21 行目: 方向 d=1 の渋滞開始時刻の目安(i=1,...,4)を示す
22 行目: 方向 d=2 の渋滞開始時刻の目安(i=1,...,4)を示す
23 行目: 方向 d=3 の渋滞開始時刻の目安(i=1,...,4)を示す
24 行目: 方向 d=4 の渋滞開始時刻の目安(i=1,...,4)を示す
25 行目: 信号の周期 P_{\text{light}}=6 を示す
26 行目: 車の故障警告期間 T_{\text{warning}}=5 を示す
27 行目: 時間ステップの最大値 T_{\max}=10000 を示す
0 \rightarrow 1
NOT_BROKEN
0 0 0 0
0
1
1 14
1
1
時刻 t=0 で以下の情報が与えられる:
1 行目: 車は正常な状態である (NOT_BROKEN)
2 行目: 渋滞は発生していない
3 行目: 新たにキャンセルされた注文の数は 0 である
4 行目: 新たに 1 つの注文があった
5 行目: 新規注文のIDは 1 であり、届け先は頂点 14 である
6 行目: 車は店に居るので、 1 つの注文に対応する荷物を車に積んだ
7 行目: 荷物に対応する注文IDは 1 である
9
コンテスタントは車を頂点 9 に向けて距離 1 だけ進める
OK
0
最初の行は車の行動が実行可能であることを示す。2 行目は配達が行われなかったことを表す
1 \rightarrow 2
NOT_BROKEN
0 0 0 0
0
1
2 16
0
時刻 t=1 で以下の情報が与えられる:
1 行目: 車は正常な状態である (NOT_BROKEN)
2 行目: 渋滞は発生していない
3 行目: 新たにキャンセルされた注文の数は 0 である
4 行目: 新たに 1 つの注文があった
5 行目: 新規注文のIDは 2 であり、届け先は頂点 16 である
6 行目: 車は店に居ないので、荷物は車に積まれなかった
9
コンテスタントは車を頂点 9 に向けて距離 1 だけ進める
OK
0
車はスピードウェイに入った。このとき信号は青である。したがって、最初の行は車の行動が実行可能であることを示す。2 行目は配達が行われなかったことを表す
2 \rightarrow 3
NOT_BROKEN
0 0 0 0
0
0
0
時刻 t=2 で以下の情報が与えられる:
1 行目: 車は正常な状態である (NOT_BROKEN)
2 行目: 渋滞は発生していない
3 行目: 新たにキャンセルされた注文の数は 0 である
4 行目: 新たに発生した注文の数は 0 である
5 行目: 荷物は車に積まれなかった
10
コンテスタントは車を頂点 10 に向けて距離 1 だけ進める
OK
0
最初の行は車の行動が実行可能であることを示す。2 行目は配達が行われなかったことを表す
3 \rightarrow 4
NOT_BROKEN
0 0 0 0
0
0
0
時刻 t=3 で以下の情報が与えられる:
1 行目: 車は正常な状態である (NOT_BROKEN)
2 行目: 渋滞は発生していない
3 行目: 新たにキャンセルされた注文の数は 0 である
4 行目: 新たに発生した注文の数は 0 である
5 行目: 荷物は車に積まれなかった
11
コンテスタントは車を頂点 11 に向けて距離 1 だけ進める
OK
0
最初の行は車の行動が実行可能であることを示す。2 行目は配達が行われなかったことを表す
4 \rightarrow 5
NOT_BROKEN
1 0 0 0
0
0
0
時刻 t=4 で以下の情報が与えられる:
1 行目: 車は正常な状態である (NOT_BROKEN)
2 行目: 渋滞がスピードウェイの方向 d=1 で発生している
3 行目: 新たにキャンセルされた注文の数は 0 である
4 行目: 新たに発生した注文の数は 0 である
5 行目: 荷物は車に積まれなかった
15
コンテスタントは車を頂点 15 に向けて距離 1 だけ進めようとする
JAM
0
最初の行は車が渋滞により進めなかったことを示す。そのため、車は頂点 11 にとどまる。2 行目は配達が行われなかったことを表す
5 \rightarrow 6
NOT_BROKEN
1 0 0 0
0
0
0
時刻 t=5 で以下の情報が与えられる:
1 行目: 車は正常な状態である (NOT_BROKEN)
2 行目: 渋滞がスピードウェイの方向 d=1 で発生している
3 行目: 新たにキャンセルされた注文の数は 0 である
4 行目: 新たに発生した注文の数は 0 である
5 行目: 荷物は車に積まれなかった
15
コンテスタントは車を頂点 15 に向けて距離 1 だけ進めようとする (依然としてこの方向には渋滞が発生している)
OK
0
最初の行は車が運良く進めたことを示す。2 行目は配達が行われなかったことを表す
6 \rightarrow 7
NOT_BROKEN
1 0 0 0
0
0
0
時刻 t=6 で以下の情報が与えられる:
1 行目: 車は正常な状態である (NOT_BROKEN)
2 行目: 渋滞がスピードウェイの方向 d=1 で発生している
3 行目: 新たにキャンセルされた注文の数は 0 である
4 行目: 新たに発生した注文の数は 0 である
5 行目: 荷物は車に積まれなかった
14
コンテスタントは車を頂点 14 に向けて距離 1 だけ進める
OK
0
最初の行は車の行動が実行可能であることを示す。2 行目は配達が行われなかったことを表す
7 \rightarrow 8
NOT_BROKEN
0 0 0 0
1
2
0
0
時刻 t=7 で以下の情報が与えられる:
1 行目: 車は正常な状態である (NOT_BROKEN)
2 行目: 渋滞は発生していない
3 行目: 新たにキャンセルされた注文の数は 1 である
4 行目: キャンセルされた注文のIDは 2 である
5 行目: 新たに発生した注文の数は 0 である
6 行目: 荷物は車に積まれなかった
14
コンテスタントは車を頂点 14 に向けて距離 1 だけ進める
OK
1
1
最初の行は車の行動が実行可能であることを示す。2 行目は 1 つの注文が配達されたことを示す。3 行目は配達された注文のIDが 1 であることを示す
8 \rightarrow 9
WARNING 5
0 0 0 0
0
0
0
時刻 t=8 で以下の情報が与えられる:
1 行目: 車は故障警告状態であり、あと 5 ステップで故障する (WARNING 5)
2 行目: 渋滞は発生していない
3 行目: 新たにキャンセルされた注文の数は 0 である
4 行目: 新たに発生した注文の数は 0 である
5 行目: 荷物は車に積まれなかった
9
コンテスタントは車を頂点 9 に向けて距離 1 だけ進める
OK
0
最初の行は車の行動が実行可能であることを示す。2 行目は配達が行われなかったことを表す
9 \rightarrow 10
WARNING 4
0 0 0 0
0
0
0
時刻 t=9 で以下の情報が与えられる:
1 行目: 車は故障警告状態であり、あと 4 ステップで故障する (WARNING 4)
2 行目: 渋滞は発生していない
3 行目: 新たにキャンセルされた注文の数は 0 である
4 行目: 新たに発生した注文の数は 0 である
5 行目: 荷物は車に積まれなかった
9
コンテスタントは車を頂点 9 に向けて距離 1 だけ進める
WAIT 2
0
最初の行は車の行動が実行可能であることを示す。したがって車はスピードウェイ上の頂点 9 に到達する。しかし赤信号のため、 2 ステップの間、車は現在の頂点にとどまらなければならない。2 行目は配達が行われなかったことを表す
10 \rightarrow 11
WARNING 3
0 0 0 0
0
0
0
時刻 t=10 で以下の情報が与えられる:
1 行目: 車は故障警告状態であり、あと 3 ステップで故障する (WARNING 3)
2 行目: 渋滞は発生していない
3 行目: 新たにキャンセルされた注文の数は 0 である
4 行目: 新たに発生した注文の数は 0 である
5 行目: 荷物は車に積まれなかった
-1
赤信号のため、コンテスタントは頂点 9 に車をとどめなくてはならない (とどめなかった場合、 NG となる)
WAIT 1
0
最初の行は車の行動が実行可能であることを示す。しかし赤信号のため、1 ステップの間、車は現在の頂点にとどまらなければならない。2 行目は配達が行われなかったことを表す
11 \rightarrow 12
WARNING 2
0 0 0 0
0
0
0
時刻 t=11 で以下の情報が与えられる:
1 行目: 車は故障警告状態であり、あと 2 ステップで故障する (WARNING 2)
2 行目: 渋滞は発生していない
3 行目: 新たにキャンセルされた注文の数は 0 である
4 行目: 新たに発生した注文の数は 0 である
5 行目: 荷物は車に積まれなかった
-1
赤信号のため、コンテスタントは頂点 9 に車をとどめなくてはならない (とどめなかった場合、 NG となる)
OK
0
最初の行は車の行動が実行可能であることを示す。2 行目は配達が行われなかったことを表す
12 \rightarrow 13
WARNING 1
0 0 0 0
0
0
0
時刻 t=12 で以下の情報が与えられる:
1 行目: 車は故障警告状態であり、あと 1 ステップで故障する (WARNING 1)
2 行目: 渋滞は発生していない
3 行目: 新たにキャンセルされた注文の数は 0 である
4 行目: 新たに発生した注文の数は 0 である
5 行目: 荷物は車に積まれなかった
1
コンテスタントは車を頂点 1 に向けて距離 1 だけ進める (信号待ちは終了)
OK
0
最初の行は車の行動が実行可能であることを示す。2 行目は配達が行われなかったことを表す
13 \rightarrow 14
BROKEN
0 0 0 0
0
0
0
時刻 t=13 で以下の情報が与えられる:
1 行目: 車は故障状態となった。(BROKEN) (コンテスタントは行動 -1 を出力しなければならない)
2 行目: 渋滞は発生していない
3 行目: 新たにキャンセルされた注文の数は 0 である
4 行目: 新たに発生した注文の数は 0 である
5 行目: 荷物は車に積まれなかった
1
コンテスタントは車を頂点 1 に向けて距離 1 だけ進めようとする
NG
最初の行は車の行動が実行不可能であることを示す(車が故障中にも関わらず動かそうとしたため)。コンテスタントはプログラムを終了させなければならない。(もしコンテスタントが一つ前のステップで車を店に戻せていたら、車は修理され、車の状態は正常状態 NOT_BROKEN となっていた)。2 行目は配達が行われなかったことを表す

出力の flush について

この問題では出力を flush する必要がある。例として、主要言語において -1 と出力して flush する例は以下の通りである。

C++

std::cout << "-1" << std::endl;

Java

System.out.println("-1");

Python 3.4

print("-1", flush=True)

サンプルコード C

この問題について、以下のツールキット一式はここからダウンロードできます。

  • 入力サンプルジェネレータ
  • テスター

また、ビシュアライザもここにご用意しております。

Problem Setting

Overview

  • Concept: Similar to the first contest, the contestant will run a delivery service. Customers will place orders with the contestant shop. Each order has a unique \text{ID} and should be delivered to the corresponding customer. The contestant's delivery service has one car. The car will fetch the ordered item from the shop and deliver it to the customer.
  • Score: The goal is to deliver as many items as possible, as quickly as possible in a given amount of time T_{\text{max}}. (Orders are expected until 0.95 \times T_{\text{max}}).
  • Constraint: In this contest there is no constraint on the number of items which can be placed into the car. However, an item can only be loaded in the car, by fetching it from the shop, after the order has been placed.
  • Problem C: In this problem orders appear online, that is new orders appear, while the contestant moves the car to make as many deliveries as possible as fast as possible. In addition the planning algorithm of the service will have to master several environmental uncertainties which constitute the main difference from our previous contest.
  • New: Environmental Uncertainties:
    • Traffic jam may appear along speedways.
    • Car breakdown: The delivery car may break.
    • Order cancellation: Customers may cancel orders after a certain time.
    • Traffic lights may hinder cars from entering and crossing of speedways.
overview

Specification of Time and Space:

  • Time: In this contest we model the progress of time by integer values 0 \le t < T_{\text{max}}.
  • Map: In this contest we model a map by a simple, undirected, and connected graph G=(V, E), consisting of a set of vertices V and a set of edges E
  • Shop and customer locations: The vertices u \in V are labeled from 1 to |V| and the vertex u=1 denotes the location of your shop, while vertices u = 2,...,|V| denote locations of potential customers. Here, |V| denotes the number of elements of the set V.
  • Streets: Each edge \left\{ u, v \right\} \in E represents a street connecting the vertices u, v \in V. The corresponding length is given by an integer edge weight d_{u, v} \ge 1.
  • New: Graph creation: The algorithm for generating the map graph based on a random seed is specified in the following pseudo-code. For further details, please see the sample code below. Note: The graph generation algorithm is different from the previous contest.
Extra Information and pseudo code: Map graph properties and map graph generator The map graph generator used in this contest produces map graphs with the following properties:
  • The graph has a pronounced two-dimensional structure of 25\times25 vertices.
  • New: Each graph has two speedway paths connecting one of the North ends to one of the South ends as well as one of the East ends to one of the West ends. Moving along the speedways is about 4 times faster than moving on other roads.
  • New: In addition there is a new bottleneck line from the North end to the South end of the map graph.
  • New: Speedways and the bottleneck line divide the graph into 6 sparsely connected regions.
  • Typical vertices have relative order frequency 1, while those in a certain centralized region has order frequency 2. Orders do neither appear on speedways nor on the shop vertex. Both of which have order frequency 0.
overview
A typical map graph (left) in an early construction stage and (right) in its final shape. (Left) : A vertex grid (dots) with North-South and East-West speedways (black dots and lines) and a (dashed) bottleneck line divides the rest of the vertices into 6 disjoint vertex sets (green shaded background). Speedways are connected to neighboring regions every 5 steps from the intersection point. Regions to the East and West of the bottleneck line are also connected every five steps from the intersection between the bottleneck line and the East-West speedway. (Right) : The final map graph with 2 speedways (thick gray line) and final vertex positions. Pink vertices which are not on speedways have relative order frequency 1. Green vertices in a center region have order frequency 2.

Pseudo-code of map graph generator:
  • Input:|V|, |E|, \mathrm{MaxDegree}=5
  • 2d vertex grid:
    • Set R \leftarrow \lfloor \sqrt{|V|} \rfloor. (In what follows we assume the case |V| = R \times R. For the treatment of a potential remainder term, please consult the code in the toolkit.)
    • Plot points (x, y) on the 2d vertex grid (0 \leq x, y \lt R) as follows. \forall u\in{1,...,|V|}
      • x \leftarrow (u-1) \mod R
      • y \leftarrow \frac{u-1-x}{R}
    • Finally, we randomly shuffle the vertex labels u. The shop is the vertex u=1.
  • Speedways and bottleneck lines
    • A North-South speedway vertex path is allocated. To this end we pick one x\in[R/2, 2R/3] and allocate all vertices with the corresponding x to the path. Neighboring speedway vertices are connected with d_{u,v}\leftarrow 1. (See figure.)
    • Similarly, an East-West speedway vertex path is allocated. To this end we pick one y\in[R/3, 2R/3] and allocate all vertices with the corresponding y to the path. Neighboring speedway vertices are connected with d_{u,v}=1. (See figure.)
    • Four speedway directions are assigned to the North, South, East, and West direction of the speedway respectively.
    • Finally, a bottleneck line is allocated at x=\xi+0.5, where \xi\in[R/6,R/3] (uniform random). (See figure.)
    • The speedways and the bottleneck line divide the remaining vertices of the vertex grid into 6 regions. (See figure.)
    • Regions neighboring the speedway are connected to the speedways every five speedway vertices (counted from the speedway intersection).
    • Similarly, regions to the East and the West of the Bottleneck line are connected every five vertex pairs (counted from the intersection of the East-West speedway with the bottleneck line).
  • Final vertex positions:
    • After creating the speedways, speedway entrances, and the connections across the bottleneck line, vertices are shifted to their final vertex position by adding a uniform random offset dx, dy \in [0, 1] , giving the final vertex position (x + dx, y + dy)\in [0,R] \times [0,R].
  • How we create a connected road networks within the 6 subregions:
    • To generate a connected road network within the six subregions, we create a complete graph G_{\text{comp}} on the vertex set u \in V, assigning each vertex pair u, v \in V \times V an edge weight W_{u, v} as follows:
      • W_{u, v}\leftarrow 1 for speedway edges
      • W_{u, v}\leftarrow \mathrm{EuclideanDistance} of vertex positions for all vertex pairs u,v with both u and v within the same region.
      • previously assigned edges for crossing the bottleneck line and entering the speedway are also assigned the Euclidean distance of the corresponding vertex positions.
      • Finally, W_{u, v}\leftarrow \infty, for all remaining vertex pairs with vertices in mutually distinct regions.
    • Next, we construct a minimum spanning tree of G_{\text{comp}}, by extending the edges which have already been assigned previously (speedways, speedway entrance, and connections across bottle neck line) to a full tree. The |V|-1 edges of the minimum spanning tree give a connected graph. An edge weight d_{u,v} \leftarrow \lceil 4 \times W_{u, v} \rceil is assigned to the newly added edges as well as the bottleneck line connections and the speedway entrances.
  • How we add side roads:
    • To create a network of side roads, we successively add |E|-(|V|-1) edges to the graph G as follows:
      • Update \mathrm{cost}(u,v).
      • Among the vertex pairs \left( u, v \right) \in V\times V, not yet connected by an edge, select a pair with minimal \mathrm{cost}(u,v).
      • Assign the edge weight d_{u,v} \leftarrow \lceil 4 \times W_{u, v} \rceil .
    • Here, \mathrm{cost}(u,v) is essentially based on the Euclidean distance of vertices, giving preference to connecting nearby vertices with low degree. In addition, preference is given to side roads along the rectangular grid, to avoid too many bridges. The detailed definitions are as follows:
      • Define \mathrm{degree}(u), the degree of vertex u\in V as the number of incident edges.
      • Define \mathrm{color}(u) for each vertex u\in V according to its original position (x,y) on the vertex grid as:
        • If x+y is even : \mathrm{color}(u) = 0
        • If x+y is odd : \mathrm{color}(u) = 1
      • Define a factor f(u,v) as follows:
        • If \mathrm{color}(u) and \mathrm{color}(v) are the same : Set \mathrm{f}(u,v) = 5
        • If \mathrm{color}(u) and \mathrm{color}(v) are different : Set \mathrm{f}(u,v) = 1
      • Define a factor g(u) as follows:
        • If \mathrm{degree}(u) \lt \mathrm{MaxDegree} : Set g(u)=1
        • If \mathrm{degree}(u) \geq \mathrm{MaxDegree} : Set g(u)=\infty
      • Finally, the cost is defined as follows:
        • \mathrm{cost}(u,v) = W_{u,v}\times \mathrm{degree}(u) \times \mathrm{degree}(v) \times f(u,v) \times g(u) \times g(v).
  • How we assign order frequencies:
    • Assign each vertex u \in V an order frequency f_u \in \left\{0,1,2\right\}.
    • Init the order frequency of the shop vertex: f_1 \leftarrow 0.
    • Init the order frequency of the other vertices: f_u \leftarrow 1
    • Now determine vertices with order frequency 2. For this draw a uniform random center point c=(c_x,c_y)\in [R/4,3R/4]\times[R/4,3R/4] and then for all vertices u=2,...,|V| do:
      • If \mathrm{EuclideanDistance}(c,u)\le R/8 + \mathrm{uniformRandom}[0,R/8]: f_{u} \leftarrow 2
    • Finally, for all vertices u along a speedway, the order frequency is set as: f_u \leftarrow 0.

Specification of Car Locations and Moves:

In order to make deliveries you will operate a delivery car, which can take positions and make moves as specified below.

  • Car position: A car can generally take two types of position:

    • on a vertex u \in V.
    • on an edge \left\{ u, v \right\} \in E. More specifically, it is located at a distance x (0 \lt x \lt d_{u, v}) from u to v .
  • Car move: At each step 0 \le t < T_{\text{max}} you have to choose one of the following actions in order to control your delivery car.

    • stay: stay at the current position.
    • move w: Take one step towards vertex w \in V.

    In case of choosing move w, w must obey the following constraints. If any of the following conditions is violated, the host code will output NG and the contestant should terminate the program, ultimately leading to WA (an incorrect answer).

    • w must be a vertex, i.e., w \in V.
    • If the car is on vertex u \in V, there must be an edge connecting u and v, i.e., \left\{ u, w \right\} \in E.
    • If the car is on the edge \left\{ u, v \right\} \in E, w must either be w = u or w = v.

  • New: A contestant's move may be rejected, if a contestant moves along a speedway direction which is blocked by a traffic jam.

  • New: A contestant's may be required to wait at a traffic light, after entering the speedway.
Car position and moves

Orders, Deliveries, and Constraints:

  • Orders: Throughout the contest each order is characterized by three quantities: A unique order ID, a vertex v \in V indicating the order destination, and the order time t at which the order appears. For the detailed format see below.
  • Order generation: At each time 0 \le t \le T_{\text{last}} = 0.95 \times T_{\text{max}} at most one new order can appear with probability p_{\text{order}}(t). In case there is an order, the order destination i is chosen from the vertex set V with probability proportional to the order frequency f_i. For details, see the pseudo-code below or the sample code further below.
Pseudo code: Order generation
  • Input: Last order time T_{\text{last}} and average order probability p_{\text{order}}(t).
  • Init: \mathrm{ID} \leftarrow 0.
  • For each step t = 0, ..., T_{\text{last}} do:
    • Generate a uniform random number r \in [0,1] .
    • If r \le p_{\text{order}}(t) :
      • Select a vertex position u \in V at random with probability proportional to the order frequency f_{u} of the vertex.
      • \mathrm{ID} \leftarrow \mathrm{ID} + 1
      • place order (new order ID, order time t, vertex position u \in V )
    • Else: place no order
  • Note: The average order probability is defined as follows:
  • p_{\text{order}}(t) = \begin{cases} t / T_{\text{peak}}, & \text{if } 0\le t \lt T_{\text{peak}}, \\ (T_{\text{last}} - t) / (T_{\text{last}}- T_{\text{peak}}), & \text{if } T_{\text{peak}} \le t \lt T_{\text{last}}, \\ 0, & \text{if } T_{\text{last}} \le t, \end{cases}
  • where T_{\text{last}}:=0.95 \times T_{\max} and T_{\text{peak}} is drawn randomly uniform from the interval [0, T_{\text{last}}].
  • Note: The value of T_{\text{peak}} will not be given as an input.
  • Delivery: To deliver an order, the contestant must do the following steps after the order has been placed:
    • (1st) Move the car onto the shop: Note: When moving a car onto the shop, all orders with order time less than or equal to the current time, will be transfered into the car. On the other hand, orders which have not appeared yet, cannot be placed into the car.
    • (2nd) Move the car to the customer position: To finalize a delivery, move the car onto the vertex of the customer position. Note: Orders which have not been transfered into the car yet or orders which are cancelled already, will not be delivered, even if you arrive at the customer position.
constraint image
  • Constraints: Throughout the contest, we assume each order has a unique \text{ID} and should be delivered to the corresponding customer. It is further assumed that an unlimited number of orders can be placed in the car.

  • New: Orders may be canceled by impatient costumers. For details see the event section below.

New: Environmental Uncertainties

The delivery planning has to master several environmental uncertainties

  • Traffic jam may appear along speedways. If a new traffic jam appears, it entirely blocks one of the four possible speedway directions. Note that, a car traveling along a speedway direction blocked by a traffic jam, can only move forward in 10\% of the cases. In 90\% of the cases, it will be forced to stay on its current position. For details please see the pseudo-code or the code in the distributed toolkit.

    Pseudo code: Traffic jam
    • Given: p_{\text{duration}}(t) // Distribution of traffic jam durations.
    • Given: p_{\text{delay}}(t) // Delay time distribution, describing delay of traffic jam outbreak after peak point.
    • Input: p_{\text{jam}}=0.25 // Probability for a single traffic jam to break out.
    • Input: p_{\text{move}}=0.1 // Probability to accept a car move along a jammed direction of a speedway.

      // Handling traffic jam upon initialization
    • For each of the four speedway directions d=1,2,3,4 we sample four points in time t_{d,i} with i=1,2,3,4 from a uniform random distribution and order them in time.
      • t_{d,i} \sim \mathrm{uniformRandom}[0,T_{\max})
      • \forall d : t_{d,1} \le t_{d,2} \le t_{d,3} \le t_{d,4}
    • Each t_{d,i} defines a point in time after which a traffic jam can appear with probability p_{\text{jam}}. If the traffic jam breaks out it is delayed for some time described by p_{\text{delay}}(t) and has a duration described by p_{\text{duration}}(t) as follows:
      • For all pairs (d,i) with d = 1,...,4 and all i = 1, ..., 4 do:
        • if \mathrm{uniformRandom}[0,1] \le p_{\text{jam}}: // traffic jam appears
          • Sample delay: \delta_{d,i} \sim p_{\text{delay}}(t)
          • A traffic jam along direction d will start at: t_{\text{start}, d, i} \leftarrow t_{d,i} + \delta_{d,i}
          • Sample duration: \Delta_{\text{jam}, d, i} \sim p_{\text{duration}}(t)
          • The traffic jam along direction d will end at: t_{\text{end}, d, i} \leftarrow t_{\text{start}, d, i} + \Delta_{\text{jam}, d, i}
        • Else: // no traffic jam appears
    • For each direction the intervals [t_{\text{start}, d, i}, t_{\text{end}, d, i}] are collected in a list. Note: Overlapping intervals will be unified.
    • The contestant algorithm will receive all 16 t_{d,i} as an input. On the other hand, the traffic jam intervals [t_{\text{start}, d, i}, t_{\text{end}, d, i}] will not be provided upon initialization.

      // Handling traffic jam during the online delivery phase
    • For t=0,..., T_{\max}-1 do:
        // Notifying the contestant of traffic jam
      • For d=1,2,3,4 do:
        • If t is in one of the traffic jam intervals t\in [t_{\text{start}, d, i}, t_{\text{end}, d, i}]:
          • Send \mathrm{jam}_d=1 to contestant
        • Else:
          • Send \mathrm{jam}_d=0 to contestant
        // Processing contestant move
      • Check validity of move as usual.
      • If (no traffic jam): Move car as instructed.
      • Else if (car on speedway) and (move in direction d) and (direction d has a traffic jam):
        • If \mathrm{randomUniform}[0,1] \le p_{\text{move}}:
          • accept move, update position, and output OK to notify contestant
        • Else:
          • reject move, stay at current position, and output JAM to notify contestant

    • The distribution of traffic jam durations is an exponential with mean \mu=1000. For further details, see comment on distributions below or check the toolkit.
    • The distribution of traffic jam delays is a power-law distribution characterized by \mathrm{median}=100 and its exponent characterized by \epsilon=3. For further details, see comment on distributions below or check the toolkit.

  • Car breakdown: The delivery car may break down. Several steps before suffering a car break down, the contestant receives a WARNING t upon which the user is guaranteed t steps to return to the shop and repair the car. If the contestant fails to return to the shop within the given time, the contestant receives the BROKEN signal, upon which the car cannot move for 300 moves. For details please see the pseudo-code or the code in the distributed toolkit.

    Pseudo code: Car breakdown
    • Given: Distribution of car ok time p_{\text{car ok}}(t).
    • Given: The return time at first car breakdown warning T_{\text{warning}}.
    • Init: t_{\text{car}} \sim p_{\text{car ok}}(t) and \mathrm{carStatus} = 0 // car ok
    • For t=0,..., T_{\max}-1 do:
        // Switching of car status
      • if \mathrm{carStatus} == 0 and t_{\text{car}} == 0: // enter warning status
        • t_{\text{car}} \leftarrow T_{\text{warning}}
        • \mathrm{carStatus} \leftarrow 1 // warning status
      • if \mathrm{carStatus} == 1 and t_{\text{car}} == 0: // enter car broken status
        • t_{\text{car}} \leftarrow 300
        • \mathrm{carStatus} \leftarrow 2 // car broken
      • if (\mathrm{carStatus} == 1 and current position is shop vertex) or (\mathrm{carStatus} == 2 and t_{\text{car}} == 0:) // repair car
        • t_{\text{car}} \leftarrow p_{\text{car ok}}(t)
        • \mathrm{carStatus} \leftarrow 0 // car not broken
      • // Sending of Signal status
      • if \mathrm{carStatus} == 0: Send NOT_BROKEN
      • if \mathrm{carStatus} == 1: Send WARNING t // t = t_{\text{car}}
      • if \mathrm{carStatus} == 2: Send BROKEN
      • // Receiving contestant move
      • \mathrm{move} \leftarrow from contestant
      • // Processing contestant move
      • if \mathrm{carStatus} \in \{0,1\} : standard procedure
      • if (\mathrm{carStatus} == 2 and \mathrm{move} is not -1:)
        • Send: NG // notifies contestant of invalid move
      • // Decrement timer
      • t_{\text{car}} \leftarrow t_{\text{car}} - 1
      Note:
    • p_{\text{car ok}}(t) generates random variable whose inverse is sampled from a power-law distribution with \mathrm{median} = \frac{1}{T_{\max}} and exponent characterized by \epsilon = 2.5. For further details, see comment on distributions below or check the toolkit.
    • If \mathrm{carStatus} == 0 then t_{\text{car}} is unknown to the contestant.
    • If \mathrm{carStatus} == 2, i.e., the car is broken, the contestant code must send the input -1 (stay), otherwise the result will be WA (wrong answer).

  • Order cancellation: Customers, who had to wait for their orders for more than T_{\text{wait}}=2000 steps, are allowed to cancel their orders. Order cancellation is handled probabilistically as described in the following pseudo-code. For further details please consult the distributed toolkit.

    Pseudo code: Order cancellation
    • Given: T_{\text{wait}}=2000 and a distribution of extra waiting time p_{\text{extra}}(t).
    • For t=0,..., T_{\max}-1 do:
        // When generating an order with \text{ID}:
        • Sample: t_{\text{extra}} \sim p_{\text{extra}}(t)
        • t_{\text{cancel}}(\text{ID}) \leftarrow t + T_{\text{wait}} + t_{\text{extra}}
        // When updating orders:
        • For each undelivered order \text{ID} do:
          • if t_{\text{cancel}}(\text{ID}) < t : send order cancellation signal

    • Note 1: t_{\text{extra}} and t_{\text{cancel}}(\text{ID}) are unknown to the contestant.
    • Note 2: p_{\text{extra}}(t) generates random variable whose inverse is sampled from a power-law distribution with \mathrm{median} = \frac{1}{T_{\max}} and exponent characterized by \epsilon=0.5. For further details, see comment on distributions below or check the toolkit.

  • Traffic lights: When entering into a speedway a car may have to wait at the traffic light. In particular, access to vertices which constitute a speedway from vertices outside of a speedway is periodically granted, depending on the time t. Note that this will also affect cars which simply drive across a speedway. For details, refer to the following pseudo code or distributed toolkit.

    Pseudo code: Traffic light
    • Input: Signal period P_{\text{light}}
    • For t=0,..., T_{\max}-1 do:
      • If (car has moved onto a speedway vertex from non-speedway vertex) or (car received WAIT signal in previous step):
        • if (\lfloor t / P_{\text{light}} \rfloor \mod 2) == 0: // green traffic light
          • the contestant move receives an OK verdict
          • the car moves onto the speedway vertex
          • the next move can be decided in a standard manner
        • else: // red traffic light
          • x \leftarrow P_{\text{light}} - \left(t \mod P_{\text{light}}\right)
          • the contestant move receives a WAIT x verdict
          • the car moves onto the speedway vertex
          • the car is required to stay on the current speedway vertex for the next x steps
    • Note: Unlike other events, this event is deterministic.

  • Definitions of the utilized probability distributions can be found in the following details section. For further details please see the code distributed with the toolkit.

    Definitions: Probability distributions
    • Throughout the contest we use three types of random variables: (i) Exponentially distributed random variables, (ii) power-law distributed random variables, and (iii) random variables which are the inverse of a power-law distributed variable. Power-law distributed variables have heavy tails and lead to many large outliers. Random variables whose inverse is drawn from a power-law have many small outliers.
    • All random variables are defined in the range t \in [0,\infty).
    • Exponential distribution:
      • Parameter: \mu (mean)
      • Probability density: p(t) = \frac{1}{\mu}\exp{\left(-\frac{t}{\mu}\right)}
      • Tail probability: P(t \ge s) := \int_{s}^{\infty} p(t) \text{d}t = \exp{\left(-\frac{s}{\mu}\right)}
      • The traffic jam duration is sampled from this type of distribution.
    • Power-law distribution
      • Parameters: \epsilon (characterizes the exponent) and the \mathrm{median}
      • Derived scaling parameter: \mu = \frac{\mathrm{median}}{2^{\frac{1}{\epsilon}} - 1}
      • Probability density: p(t)= \frac{\epsilon}{\mu}\left(1+\frac{t}{\mu}\right)^{-(1+\epsilon)}
      • Tail probability: P(t \ge s) := \int_{s}^{\infty} p(t) \text{d}t = \left(1+\frac{s}{\mu}\right)^{-\epsilon}
      • The traffic jam outbreak delay times are sampled from this type of distribution.
    • Random variables with inverse distributed as power-law.
      • Parameters: \epsilon, \mathrm{median}
      • The variable x:=1/t is sampled from a power-law distribution p(x) with parameters \epsilon, \mathrm{median}
      • In the algorithm we sampling a variable x from the power-law distribution with \epsilon, \mathrm{median} and then take its inverse to get the desired variable as t \leftarrow 1/x.
      • The duration during which the car is not broken and extra waiting times for costumer cancellation are sampled from this type of distribution.

Scoring

  • During the contest the total score of a submission is determined by summing the score of the submission with respect to 30 input cases.
  • After the contest a system test will be performed. To this end, the contestant's last submission will be scored by summing the score of the submission on 100 previously unseen input cases.
  • For each input case, the score is calculated as follows:

    \text{Score} = \sum_{i \in D} {(T_{\text{max}})}^{2} - {(\mathrm{waitingTime}_i)}^{2},

    Here we use the following definitions:
    • D : the set of orders delivered until t=T_{\text{max}}
    • the waiting time of the ith order: \mathrm{waitingTime}_i = \mathrm{deliveredTime}_i - \mathrm{orderedTime}_i.
    • Note that an input case giving the output WA will receive 0 points.

Particulars of Problem C:

Problem C is an interactive contest, in which the contestant code successively receives updates on newly generated and delivered orders from a host code, while simultaneously servicing the customer by moving the car to a neighboring position in every step t=0,...,T_{\max}-1. In addition, the planning algorithm of the service, will have to master changing circumstances such as traffic jam, car breakdown, order cancellation, and traffic lights.

The precise flow which details the interaction of the contestant and host code is shown below.

Contestant Code Host Code
Generate and output graph G
New: Generate traffic jam and output potential traffic jam outbreak times t_{i,d}
+ New:Time t: Broadcast car status
+ New:Time t: Broadcast traffic conditions
+ New: Time t: Check and output canceled orders
+ Time t: Generate and output new orders
+ Time t: If on shop, output orders loaded into car
+ Time t: Determine and output a move
+ Check feasibility of move; If move unfeasible: output WA, If feasible: update car position, New: Report actual move (May differ from requested move, if on jammed speedway or in front of red traffic light)
+ Time t+1: update and output information on delivered items (if any)

Note: The host code outputs the graph, the order frequencies and the traffic jam information only once. The processes marked by a "+" on the left side of the table are repeated iteratively for integers t in t = 0,..., T_{\max} - 1.


Interactive Input/Output Format through the Standard IO

Initialization

At first, the host code will output a graph G and the order frequencies f_{i} for each vertex i, which are proportional to the probability of an order to appear at vertex i. In addition, the times t_{d,i}, \cdots, t_{d,i} for potential traffic jam outbreaks along direction d, the switching period of a traffic light P_{\text{light}} and the total number of steps T_{\max} is provided.

|V| |E|
u_1 v_1 d_{u_1, v_1} e_{u_1, v_1} e_{v_1, u_1}
u_2 v_2 d_{u_2, v_2} e_{u_2, v_2} e_{v_2, u_2}
\vdots
u_{|E|} v_{|E|} d_{u_{|E|}, v_{|E|}} e_{u_{|E|}, v_{|E|}} e_{v_{|E|}, u_{|E|}}
f_1 f_2 \ldots f_{|V|}
t_{1,1}, \cdots, t_{1,4}
\vdots
t_{4,1}, \cdots, t_{4,4}
P_{\text{light}}
T_{\text{warning}}
T_{\max}
  • First line: |V| number of vertices, |E| number of edges
  • The next |E| lines: The edges of the graph. In particular, the ith line denotes the vertices u_i and v_i which form an edge, along with the corresponding edge weight d_{u_i, v_i}. In addition, e_{u_i, v_i} and e_{u_i, v_i} denote the street type along edge direction u_i \to v_i) and v_i \to u_i, respectively. In particular:
    • e_{u_i, v_i} = 0 : The edge direction u_i \to v_i connects two standard roads.
    • e_{u_i, v_i} = d \in {1,2,3,4} : The edge direction u_i \to v_i is along the speedway of direction d.
    • e_{u_i, v_i} = 5 : The edge direction u_i \to v_i has its endpoint vertex v_i on a speedway.
    • e_{u_i, v_i} = 6 : The edge direction u_i \to v_i has its start vertex u_i on a speedway.
  • The next line: The order frequencies f_i which determine the probability of an order at vertex i as p_{i}=\frac{f_{i}}{\sum_{i}f_{i}}.
  • The next four lines: Each line t_{d,1}, \cdots, t_{d,4} (d=1,\cdots,4) denotes four points in time after which a new traffic jam may outbreak along direction d.
  • The next line: Denotes the light period P_{\text{light}}.
  • The next line: Denotes the period T_{\text{warning}}, after which a car breaks, if the contestant does not return to the shop.
  • The last line: The total number of car position updates T_{\max}.

Interactive Loop

At time t we first obtain the following information through the standard input.

\mathrm{CAR\_STATUS}
\mathrm{jam}_{1} \mathrm{jam}_{2} \mathrm{jam}_{3} \mathrm{jam}_{4}
N_{\text{cancel}}
\mathrm{cancel\_id}_1
\mathrm{cancel\_id}_2
\vdots
\mathrm{cancel\_id}_{N_{\text{cancel}}}
N_{\text{new}}
\mathrm{new\_id}_1 \mathrm{dst}_1
\mathrm{new\_id}_2 \mathrm{dst}_2
\vdots
\mathrm{new\_id}_{N_{\text{new}}} \mathrm{dst}_{N_{\text{new}}}
N_{\text{put}}
\mathrm{put\_id}_1
\mathrm{put\_id}_2
\vdots
\mathrm{put\_id}_{N_{\text{put}}}
  • The first line represents the \mathrm{CAR\_STATUS} which can take one of the following values:
    • NOT_BROKEN : Denotes that the car is in good shape.
    • WARNING t : Denotes that the car will break in t steps, if not returning to the shop.
    • BROKEN : Denotes that the car is currently broken and cannot move in this step. In this case, the contestant should output stay, i.e. -1 or otherwise the answer will become NG.
  • The second line broadcasts traffic conditions along the speedway directions d=1,2,3,4. In particular, if \mathrm{jam}_d is 0, direction d has no traffic jam. On the other hand, if \mathrm{jam}_d is 1, direction d is jammed.
  • The next line : N_{\text{cancel}} represents the number of orders which have been canceled at time t.
  • The subsequent N_{\text{cancel}} lines indicate canceled orders. In particular, the ith line indicates that the order with ID \mathrm{cancel\_{id}}_i has been canceled.
  • The next line : N_{\text{new}} represents the number of new orders which appeared at time t.
  • The next N_{\text{new}} lines give the newly generated order information. The ith order information indicates that the order ID \mathrm{new\_{id}}_i of the new order, while \mathrm{dst}_i denotes the vertex to which the customer wishes the order to be delivered.
  • The next line : N_{\text{put}} represents the number of items transfered into the car at time t.
    • If the car is not at the vertex of the store N_{\text{put}} will be zero.
  • The subsequent N_{\text{put}} lines indicate the order information for the newly loaded items. In particular, the ith line indicates that the order ID corresponding to the product loaded in the car is \mathrm{put\_{id}}_i.

Next, in order to move the delivery car to a neighboring position the contestant code must at every time t (0 \leq t \lt T_{\max}) output the following \mathrm{command} to the standard output.

\mathrm{command}

Here, \mathrm{command} must be of the following form

  • If you want the car to stay at its current position, send -1 to the standard output
  • If you want the car to move one step towards a neighboring vertex move w, send w to the standard output

Note: In case you choose move w, w must meet all of the following conditions. If any of the following conditions is violated, the host code will output NG and the contestant should terminate the program, ultimately leading to WA (incorrect).

  • w is a vertex index with w \in \left\{1, ... , |V|\right\}
  • If the car is on a vertex u, the edge \left\{ u, w \right\} \in E must exist
  • If the car is on an edge \left\{ u, v \right\}, w must either be w = u or w = v

Moreover, if the \mathrm{CAR\_STATUS} is BROKEN, the contestant is required to send -1 to the standard output. A failure to do so, will result in the the host code judging the move as NG, ultimately leading to WA, i.e., a wrong answer as described further below.

After the contestant action at time t is send to the standard output, the host code will send the following information about time t + 1 to the standard input.

\mathrm{verdict}
N_{\text{achieve}}
\mathrm{achieve\_id}_1
\mathrm{achieve\_id}_2
\vdots
\mathrm{achieve\_id}_{N_{\text{achieve}}}
  • \mathrm{verdict} is a string indicating whether your action at time t was valid. It can be one of the two following options.
    • OK: Indicating that the requested move was feasible and the car has been moved accordingly.
    • NG: Indicates that your action is infeasible. If you receive this input, you must terminate the program immediately. It is guaranteed to be WA (incorrect), if it is terminated immediately. If you do not terminate immediately the behavior is undefined.
    • JAM : Appears, if the requested move along a jammed direction was rejected. (Note: Moves along a jammed direction which have been accepted, will receive an OK, indicating that the move was executed as requested.)
    • WAIT t : Indicates that the requested move was feasible and the car has been moved accordingly. However, since the car has been moved onto a speedway vertex from outside a speedway, the contestant is now requested to wait at the traffic light for t steps, i.e., the contestant code must output -1 for the next t steps. A failure to do so will result in the verdict NG. Further note, when entering a speedway vertex during a green traffic signal, the host code will send the verdict OK.
  • N_{\text{achieve}} represents the number of orders that have been delivered at time t.
    • If the car is not at a delivery vertex, no orders have been delivered and N_{\text{achieve}}=0.
  • The subsequent N_{\text{achieve}} lines indicate the delivered orders. In particular, the ith line indicates the order ID \mathrm{achieve\_{id}}_i.

Finally, after receiving the standard input of the host code after the last step T_{\max} you must terminate the program immediately.

I/O Constraints

  • All numbers given through the standard input are integers.
  • All outputs must be integers

Initialization

  • T_{\text{max}} = 10000
  • |V| = 625
  • 1.5 |V| \leq |E| \leq 2|V|
  • 1 \leq u_{i}, v_{i} \leq |V| (1 \leq i \leq |E|)
  • 1 \leq d_{u_i, v_i} \leq \lceil 4\sqrt{2|V|} \rceil (1 \leq i \leq |E|)
  • 0 \leq e_{u_i, v_i}, e_{v_i, u_i} \leq 6 (1 \leq i \leq |E|)
  • The given graph has no self-loops, no multiple edges and is guaranteed to be connected.
  • f_1 = 0
  • f_i \in \left\{0, 1, 2 \right\} (2 \leq i \leq |V|)
  • 0 \leq t_{d,1} \leq t_{d,2} \leq t_{d,3} \leq t_{d,4} \lt T_{\text{max}} (1 \leq d \leq 4)
  • 50 \leq T_{\text{warning}} \leq 120
  • 10 \leq P_{\text{light}} \leq 30

Interactive Loop

  • \mathrm{CAR\_STATUS} \in \{ NOT_BROKEN, WARNING t, BROKEN\}
  • \mathrm{jam}_{1}, \mathrm{jam}_{2}, \mathrm{jam}_{3}, \mathrm{jam}_{4} \in \{0,1\}
  • 0 \leq N_{\text{new}} \leq 1
  • 1 \leq \mathrm{new\_id}_{i} \leq T_{\text{last}}+1 (1 \leq i \leq N_{\text{new}}). Note: If all orders are generated by the order generation rule as explained above, the total number of orders is at most T_{\text{last}}+1. Therefore, the possible range of \mathrm{new\_id}_{i} should be from 1 to T_{\text{last}}+1.
  • The order IDs \mathrm{new\_{id}}_i are unique.
  • 2 \leq \mathrm{dst}_i \leq |V| (1 \leq i \leq N_{\text{new}})
  • 0 \leq N_{\text{cancel}} \leq T_{\text{last}}+1
  • 1 \leq \mathrm{cancel\_id}_{i} \leq T_{\text{last}}+1 (1 \leq i \leq N_{\text{cancel}}).
  • 0 \leq N_{\text{put}} \leq T_{\text{last}}+1
  • 1 \leq \mathrm{put\_id}_{i} \leq T_{\text{last}}+1 (1 \leq i \leq N_{\text{put}}).
  • The integer which the contestant outputs to the standard output at time t must either be -1 or 1 \leq w \leq |V|
  • \mathrm{verdict} \in \{OK, NG,JAM, WAIT t\}
  • 0 \leq N_{\text{achieve}} \leq T_{\text{last}}+1
  • 1 \leq \mathrm{achieve\_id}_{i} \leq T_{\text{last}}+1 (1 \leq i \leq N_{\text{achieve}}).

Input/Output Example

In this IO example, we will use the situation visualized below. In particular:

  • Graph : The example shows a graph with 16 vertices and 18 edges.
  • Speedways are marked in black and have the following directions.
    • d=1 : 3\to7\to11\to15
    • d=2 : 15\to11\to7\to3
    • d=3 : 9\to10\to11\to12
    • d=4 : 12\to11\to10\to9.
  • From step 0 to 8 : The car will deliver an order with ID 1 to vertex 14, while the order at vertex 16 will expire. The delivery route is marked by red arrows. A traffic jam is experienced at steps 4\to5.
  • From step 8 to 14 : A car breakdown warning WARNING 5 will appear and the car tries to return to the shop vertex 1 for repair. However, the traffic light at vertex 9 will output a red signal WAIT 2 requiring the car to wait two steps 11, 12.
  • In step 13 the car arrives in between the vertex pair 1, 9 and breaks, receiving a BROKEN.
  • Step 14 : An infeasible move towards the shop during car BROKEN leads to the output NG.
overview

Note: This example has been shrunk for pedagogical reasons and does not fulfill the constraints listed above.

Time Contestant Host Code Explanation
16 18
5 1 2 0 0
2 3 2 5 6
2 6 4 0 0
3 4 2 6 5
3 7 1 1 2
4 8 4 0 0
1 6 2 0 0
1 9 2 5 6
7 11 1 1 2
9 10 1 3 4
9 13 2 6 5
9 14 2 6 5
10 11 1 3 4
11 12 1 3 4
11 15 1 1 2
12 16 2 6 5
14 15 2 5 6
15 16 2 6 5
0 1 0 1 1 2 0 1 0 0 0 0 1 1 0 1
3 167 311 913
63 617 791 837
325 473 893 915
156 387 627 849
6
5
10000
The host code provides the initialization data through the standard input.
1st line: The graph has |V| = 16 vertices and |E| = 18 edges.
The next 18 lines (Line 2 - 19) denote the edges of the graph. For example:
2nd line : Indicates an edge between vertex 5 and 1 connected by a street of distance 2. Fourth digit 0 denotes that the road from 5\to1 is a standard road. Last digit 0 denotes that the road from 5\to 1 is also a standard road.
3rd line : Indicates an edge between vertex 2 and 3 connected by a street of distance 2. Fourth digit 5 denotes that road from 2\to3 leads to a speedway. Last digit 6 denotes that road from 3 \to 2 leads away from a speedway.
6th line : Indicates an edge between vertex 3 and 7 connected by a street of distance 1. Fourth digit 1 denotes that road from 3\to7 is a speedway along direction 1. Last digit 2 denotes that the road from 7\to3 is a speedway along direction 2.
20th Line : Indicates the order frequency for each vertex.
21st Line : Indicates the potential traffic jam outbreak peaks of direction one.
22nd Line : Indicates the potential traffic jam outbreak peaks of direction two.
23rd Line : Indicates the potential traffic jam outbreak peaks of direction three.
24th Line : Indicates the potential traffic jam outbreak peaks of direction four.
25th Line : The traffic light period P_{\text{light}}=6.
26th Line : Indicates the car warning period T_{\text{warning}}=5.
27th Line : T_{\max}=10000 is given.
0 \rightarrow 1
NOT_BROKEN
0 0 0 0
0
1
1 14
1
1
At time t=0 we are notified that: 1st line: Our car is NOT_BROKEN. 2nd line: There is no traffic jam along speedways. 3rd line: 0 orders have been canceled. 4th line: There is 1 new order. 5th line: The new order has ID 1 and shall be delivered to vertex 14. 6th line: There was 1 order put into the car (because we are on the shop vertex). 7th line: The order put into the car has ID 1.
9
The contestant moves one step towards vertex 9.
OK
0
The first line indicates that the move was feasible. The second line shows that no orders have been delivered.
1 \rightarrow 2
NOT_BROKEN
0 0 0 0
0
1
2 16
0
At time t=1 we are notified that: 1st line: The car is NOT_BROKEN. 2nd line: There is no traffic jam along speedways. 3rd line: 0 orders have been canceled. 4th line: There is 1 new order. 5th line: The new order has ID 2 and shall be delivered to vertex 16. 6th line: There was 0 order put into the car. (The car is not at the shop vertex.)
9
The contestant moves one step towards vertex 9.
OK
0
The car enters the speedway upon a green traffic light. Hence, the first line indicates that the move was feasible. The second line shows that no orders have been delivered.
2 \rightarrow 3
NOT_BROKEN
0 0 0 0
0
0
0
At time t=2 we are notified that: 1st line: Our car is NOT_BROKEN. 2nd line: There is no traffic jam along speedways. 3rd line: 0 orders have been canceled. 4th line: There are 0 new orders. 5th line: There were 0 orders put into the car.
10
The contestant moves the car one step towards vertex 10.
OK
0
The first line indicates that the move was feasible. The second line shows that no orders have been delivered.
3 \rightarrow 4
NOT_BROKEN
0 0 0 0
0
0
0
At time t=3 we are notified that: 1st line: the car is NOT_BROKEN. 2nd line: There is no traffic jam along speedways. 3rd line: 0 orders have been canceled. 4th line: There are 0 new orders. 5th line: There were 0 orders put into the car.
11
The contestant decided to move one step towards vertex 11.
OK
0
The first line indicates that the move was feasible. The second line shows that no orders have been delivered.
4 \rightarrow 5
NOT_BROKEN
1 0 0 0
0
0
0
At time t=4 we are notified that: 1st line: The car is NOT_BROKEN. 2nd line: There is a traffic jam along speedway direction d=1. 3rd line: 0 orders have been canceled. 4th line: There are 0 new orders. 5th line: There were 0 orders put into the car.
15
The contestant tries to move one step towards vertex 15.
JAM
0
The first line indicates that the move along traffic jam direction d=1 was rejected. The car stays on vertex 11. The second line shows that no orders have been delivered.
5 \rightarrow 6
NOT_BROKEN
1 0 0 0
0
0
0
At time t=5 we are notified that: 1st line: the car is NOT_BROKEN. 2nd line: There is a traffic jam along speedway direction d=1. 3rd line: 0 orders have been canceled. 4th line: There are 0 new orders. 5th line: There were 0 orders put into the car.
15
Again, the contestant tries to move one step towards vertex 15 (even though there is a traffic jam along this direction).
OK
0
The first line indicates that the move was accepted (lucky!). The second line shows that no orders have been delivered.
6 \rightarrow 7
NOT_BROKEN
1 0 0 0
0
0
0
At time t=6 we are notified that: 1st line: The car is NOT_BROKEN. 2nd line: There is a traffic jam along speedway direction 1. 3rd line: 0 orders have been canceled. 4th line: There are 0 new orders. 5th line: there were 0 orders put into the car.
14
The car is moved one step towards vertex 14.
OK
0
The first line indicates that the move was feasible. The second line shows that no orders have been delivered.
7 \rightarrow 8
NOT_BROKEN
0 0 0 0
1
2
0
0
At time t=7 we are notified that: 1st line: The car is NOT_BROKEN. 2nd line: There is no traffic jam along speedways. 3rd line: 1 order has been canceled. 4th line: The ID of the canceled order is 2. 5th line: There are 0 new orders. 6th line: There were 0 orders put into the car.
14
The contestant decided to move the car one step towards vertex 14.
OK
1
1
The first line indicates that the move was feasible. The second line shows that 1 order has been delivered. The third line shows that the order with ID 1 has been delivered.
8 \rightarrow 9
WARNING 5
0 0 0 0
0
0
0
At time t=8 we are notified that: 1st line: The car is about to break in 5 steps. 2nd line: There is no traffic jam along speedways. 3rd line: 0 orders have been canceled. 4th line: There are 0 new orders. 5th line: There were 0 orders put into the car.
9
The contestant moves the car towards vertex 9.
OK
0
The first line indicates that the move was feasible. The second line shows that no orders have been delivered.
9 \rightarrow 10
WARNING 4
0 0 0 0
0
0
0
At time t=9 we are notified that: 1st line: The car is about to break in 4 steps. 2nd line: There is no traffic jam along speedways. 3rd line: 0 orders have been canceled. 4th line: There are 0 new orders. 5th line: There were 0 orders put into the car.
9
The contestant moves the car towards vertex 9.
WAIT 2
0
The first line indicates that the move was feasible. The car is now on speedway vertex 9. However, due to the traffic light, the contestant is now required to wait at the current vertex for two steps. The second line shows that no orders have been delivered.
10 \rightarrow 11
WARNING 3
0 0 0 0
0
0
0
At time t=10 we are notified that: 1st line: The car is about to break in 3 steps. 2nd line: There is no traffic jam along speedways. 3rd line: 0 orders have been canceled. 4th line: There are 0 new orders. 5th line: There were 0 orders put into the car.
-1
The car stays on vertex 9 to wait for the traffic light. (A failure to do so would result in the verdict NG.)
WAIT 1
0
The first line indicates that the move was feasible. The car is still on speedway vertex 9. In addition, the contestant is required to wait at the current vertex for one more steps. The second line shows that no orders have been delivered.
11 \rightarrow 12
WARNING 2
0 0 0 0
0
0
0
At time t=11 we are notified that: 1st line: The car is about to break in 2 steps. 2nd line: There is no traffic jam along speedways. 3rd line: 0 orders have been canceled. 4th line: There are 0 new orders. 5th line: There were 0 orders put into the car.
-1
The car stays on vertex 9 to wait for the traffic light. (A failure to do so would result in the verdict NG.)
OK
0
The first line indicates that the move was feasible. The second line shows that no orders have been delivered.
12 \rightarrow 13
WARNING 1
0 0 0 0
0
0
0
At time t=12 we are notified that: 1st line: The car is about to break in 1 steps. 2nd line: There is no traffic jam along speedways. 3rd line: 0 orders have been canceled. 4th line: There are 0 new orders. 5th line: There were 0 orders put into the car.
1
The car is instructed to move one step towards vertex 1. (Waiting time along traffic light is over.)
OK
0
The first line indicates that the move was feasible. The second line shows that no orders have been delivered.
13 \rightarrow 14
BROKEN
0 0 0 0
0
0
0
At time t=13 we are notified that: 1st line: The car is BROKEN. (The contestant is required to output -1.) 2nd line: There is no traffic jam along speedways. 3rd line: 0 orders have been canceled. 4th line: There are 0 new orders. 5th line: There were 0 orders put into the car.
1
The contestant erroneously decided to move one step towards vertex 1.
NG
The first line indicates that the move was infeasible. The contestant is required to terminate its program. (Had the contestant returned to the shop vertex in a previous step, the CAR_STATUS would have recovered from WARNING t to NOT_BROKEN.)

Using the Standard Output

When returning your move instruction to the standard output, please use the flush command. As an example, consider the case where you want to output -1. This is how to do it in some of the major programming languages.

C++

std::cout << "-1" << std::endl;

Java

System.out.println("-1");

Python 3.4

print("-1", flush=True)

Sample Code C

A software toolkit for generation of input samples, scoring and testing on a local contestant environment is provided through the following link. In addition we provide software for visualizing the contestants results.

ビジュアライザ

Step
FPS
Command
Δ
Score