結果

問題 No.139 交差点
ユーザー te-sh
提出日時 2016-08-31 00:13:26
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 813 bytes
コンパイル時間 747 ms
コンパイル使用メモリ 120,272 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-12 03:56:28
合計ジャッジ時間 1,697 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range;
import std.string, std.conv;
import std.math, std.bigint, std.bitmanip, std.random;
import std.stdio, std.typecons;

alias Tuple!(int, "x", int, "w", int, "t") cross;

void main()
{
  auto rd = readln.chomp.split.map!(to!int);
  auto n = rd[0], l = rd[1];
  auto ci = iota(n)
    .map!(_ => readln.split.map!(to!int))
    .map!(rd => cross(rd[0], rd[1], rd[2]));

  auto x = 0;
  auto t = 0;

  foreach (c; ci) {
    t += c.x - x;
    x = c.x;

    if (signal(t, c) && next(t, c) - t < c.w)
      t = next(t, c);
    if (!signal(t, c))
      t = (t / c.t + 1) * c.t;

    x += c.w;
    t += c.w;
  }

  t += l - x;

  writeln(t);
}

bool signal(int t, cross c)
{
  return (t / c.t) % 2 == 0;
}

int next(int t, cross c)
{
  return (t / c.t + 1) * c.t;
}
0