結果
| 問題 |
No.139 交差点
|
| ユーザー |
okuraofvegetabl
|
| 提出日時 | 2018-04-16 10:48:39 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,551 bytes |
| コンパイル時間 | 1,268 ms |
| コンパイル使用メモリ | 158,936 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-27 03:59:58 |
| 合計ジャッジ時間 | 2,120 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:45:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | scanf("%d %d",&N,&L);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:47:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
47 | scanf("%d %d %d",&X[i],&W[i],&T[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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;
}
okuraofvegetabl