結果
| 問題 | No.139 交差点 | 
| コンテスト | |
| ユーザー |  ytft | 
| 提出日時 | 2021-03-15 19:58:47 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 474 bytes | 
| コンパイル時間 | 1,891 ms | 
| コンパイル使用メモリ | 169,260 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-07 07:52:43 | 
| 合計ジャッジ時間 | 2,819 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 28 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int func(int t,int T,int W){
    if(t%(2*T)>=T || (t+W)%(2*T)>T){
        return ((t-1)/(2*T)+1)*(2*T)+W;
    }else{
        return t+W;
    }
}
int main(){
    int N,L;
    cin>>N>>L;
    vector<int> X(N),W(N),T(N);
    for(int i=0;i<N;i++){
        cin>>X[i]>>W[i]>>T[i];
    }
    X.push_back(L);
    int time=X[0];
    for(int i=0;i<N;i++){
        time=func(time,T[i],W[i])+X[i+1]-X[i]-W[i];
    }
    cout<<time<<endl;
}
            
            
            
        