結果
問題 | No.139 交差点 |
ユーザー |
|
提出日時 | 2018-07-06 13:50:38 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 965 bytes |
コンパイル時間 | 458 ms |
コンパイル使用メモリ | 55,060 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 02:44:42 |
合計ジャッジ時間 | 1,616 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <iostream> #define REP(i,a,b) for(int i=(a); i<(b); i++) #define ll long long int using namespace std; // 交差点の始点で待つ時間を求める // ansは始点に到着した時点での経過時間 int solve(int ans, int x, int w, int t){ int wait; // 信号が変わった回数 int turn = ans / t; if (turn % 2 == 1) { return (turn + 1) * t - ans; } else { // 信号が変わるまでの残り時間 int nokori = (turn + 1) * t - ans; if (nokori >= w) return 0; else return nokori + t; } } int main(){ int n, l; cin >> n >> l; ll ans = 0; int now = 0; REP(i, 0, n){ int x, w, t; cin >> x >> w >> t; // 交差点の始点まで移動 ans += (x - now); now = x; // 交差点の始点で待つ時間を加算 ans += solve(ans, x, w, t); } ans += (l - now); cout << ans << endl; return 0; }