結果

問題 No.139 交差点
ユーザー knewknowlknewknowl
提出日時 2015-02-08 18:32:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 989 bytes
コンパイル時間 664 ms
コンパイル使用メモリ 59,452 KB
実行使用メモリ 4,436 KB
最終ジャッジ日時 2023-09-05 11:01:07
合計ジャッジ時間 2,111 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,424 KB
testcase_22 AC 2 ms
4,436 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0