結果

問題 No.139 交差点
ユーザー nanophoto12nanophoto12
提出日時 2016-01-12 00:27:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,514 bytes
コンパイル時間 672 ms
コンパイル使用メモリ 87,740 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 22:50:01
合計ジャッジ時間 1,631 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <limits>

using namespace std;

#define REP(x,y) for(int x = 0;x < (y);x++)
#define LLI long long int
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())

#define _L(x) cout<<(x)<<endl

LLI dp[101010][2]; // pos, less

int N, L;
struct Data
{
    LLI X;
    LLI W;
    LLI T;
    
    LLI GetWait(LLI time) const
    {
        LLI sdiv = time / T;
        LLI ediv = (time+W) / T;
        LLI smod = time % T;
        LLI emod = (time+W) % T;
        if(sdiv % 2 == 1)
        {
            return T - smod;
        }
        if(ediv % 2 == 0)
        {
            return 0;
        }
        if(emod == 0)
        {
            return 0;
        }
        return 2 * T - smod;
    }
};

vector<Data> values;

int main()
{
    cin >> N >> L;
    values.resize(N);
    REP(i, N)
    {
        Data e;
        cin >> e.X >> e.W >> e.T;
        values[i] = e;
    }
    LLI currentTime = 0;
    LLI currentPosition = 0;
    REP(i, N)
    {
        currentTime += values[i].X - currentPosition;
        LLI wait =values[i].GetWait(currentTime);
        //cout << wait << endl;
        currentTime += wait;
        currentTime += values[i].W;
        currentPosition = values[i].X + values[i].W;
    }
    currentTime += L - currentPosition;
    cout << currentTime << endl;
}
0