結果

問題 No.139 交差点
ユーザー k
提出日時 2020-09-28 04:02:55
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 648 bytes
コンパイル時間 1,770 ms
コンパイル使用メモリ 193,420 KB
最終ジャッジ日時 2025-01-14 23:11:31
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, l;

  int ret = 0;
  int pos = 0;

  cin >> n >> l;
  REP (i, n) {
    int x, w, t;
    cin >> x >> w >> t;

    // move to crossroad
    ret += x - pos;
    pos += x - pos;

    // wait
    int r = ret % (2 * t);
    if (r < t) {  // blue light
      if (t - r < w) {
        ret += 2 * t - r;
      }
    } else {      // red light
      ret += 2 * t - r;
    }
    
    // cross crossroad
    ret += w;
    pos += w;
  }

  ret += l - pos;
  cout << ret << endl;
  
  return 0;
}
0