結果
問題 | No.139 交差点 |
ユーザー |
![]() |
提出日時 | 2015-02-08 18:32:19 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 989 bytes |
コンパイル時間 | 529 ms |
コンパイル使用メモリ | 56,824 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-23 06:42:29 |
合計ジャッジ時間 | 1,408 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <algorithm> #include <iostream> using namespace std; int start[100010]; int atime[100010]; int n,l; bool X[100010]; int W[200]; int T[200]; void input(){ cin >> n >> l; for(int i=0;i<n;++i){ int x; cin >> x; X[x]=true; cin >> W[i] >> T[i]; } } void solve(){ atime[0] = 0; int cnt = 0; //わたった交差点の数 for(int x=0;x<=l;++x){ if(X[x]){ //交差点にいる int w = W[cnt], t = T[cnt]; if((atime[x]/t)%2 == 1){ //交差点に来たときに赤 start[x] = (atime[x]/t+1)*t; //青になるまで待つ } else if(atime[x]%t + w <= t){ //青でわたりきれる start[x] = atime[x]; } else{ //青でわたりきれないから次に青になるまで待つ start[x] = atime[x]+2*t-(atime[x]%t); } cnt++; } else{ //交差点にいない start[x] = atime[x]; } atime[x+1] = start[x]+1; } cout << atime[l] << endl; } int main(){ input(); solve(); return 0; }