結果

問題 No.139 交差点
ユーザー okuraofvegetablokuraofvegetabl
提出日時 2018-04-16 10:48:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,551 bytes
コンパイル時間 1,161 ms
コンパイル使用メモリ 144,272 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 10:51:48
合計ジャッジ時間 2,248 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef multiset<int>::iterator msi;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N,L;
int X[105],W[105],T[105];
bool check_f(int id,int time){
	if(time%T[id]==0){
		if((time/T[id])%2==0)return true;
		else return false;
	}
	if((time/T[id])%2==0)return true;
	else return false; 
}
bool check_b(int id,int time){
	if(time%T[id]==0){
		if((time/T[id])%2==1)return true;
		else return false;
	}
	if((time/T[id])%2==0)return true;
	else return false; 
}
int rest(int id,int time){
	return T[id]-(time%T[id]);
}
int main(){
	scanf("%d %d",&N,&L);
	for(int i=0;i<N;i++){
		scanf("%d %d %d",&X[i],&W[i],&T[i]);	
	}
	int pos = 0;
	int t = 0;
	for(int i=0;i<N;i++){
		t += X[i]-pos;
		pos = X[i];
		if(check_f(i,t)){
			if(check_b(i,t+W[i])){
				pos += W[i];
				t += W[i];
			}else{
				t += rest(i,t)+T[i];
				pos += W[i];
				t += W[i];
			}
		}else{
			t += rest(i,t);
			pos += W[i];
			t += W[i];
		}
	}
	t += L-pos;
	printf("%d\n",t);
	return 0;
}
0