This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize ("O3","unroll-loops")
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cassert>
#include <exception>
#include <functional>
#include <iterator>
#include <limits>
#include <locale>
#include <numeric>
#include <random>
#include <stdexcept>
#include <typeinfo>
#include <utility>
#include <tuple>
#include <cstdio>
#include <bitset>
using namespace std;
// ************ Define ************
#define FPTU ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define BUG(x) {cerr << #x << " = " << x << endl;}
#define pii pair<int,int>
#define pip pair<int,pii>
#define ppi pair<pii,int>
#define ll long long
#define ull unsigned long long
#define usi unsigned int
#define pll pair<ll,ll>
#define plp pair<ll,pll>
#define ppl pair<pll,ll>
#define ppp pair<pii,pii>
#define oo 1000111000
#define ooo 1000111000111000111
#define inf 0x3f //4557430888798830399
#define fi first
#define se second
#define vt vector
#define pb push_back
#define all(arr) arr.begin(),arr.end()
#define bit(n, i) (((n) >> (i)) & 1)
#define db(x) cerr << #x << " = " << (x) << '\n';
#define el cout<<'\n';
#define Vhai20051
int mod=1e9+7; // MODDDDDDDDDDDDD
const int maxn=1005;
int n,pos[maxn],speed[maxn],speedN,m;
ll start[maxn],L;
ll sub1(ll startN){
ll curN = startN;
ll cur0 = start[0];
for(int i=1;i<m;i++) {
ll dist = pos[i]-pos[i-1];
if(cur0==curN)
{
cur0+=dist*speed[0];
curN+=dist*speedN;
}
else if(cur0<curN) // bus[0] move first
{
if(speed[0]<=speedN) // bus[0] faster
{
cur0+=dist*speed[0];
curN+=dist*speedN;
}
else{ // busN faster -> busN can keep up with bus0
cur0+=dist*speed[0];
curN=max(curN+dist*speedN,cur0);//keep up with bus0
}
}
else{ //busN move first
if(speed[0]>=speedN) // busN faster
{
cur0+=dist*speed[0];
curN+=dist*speedN;
}
else{ // bus0 faster -> bus0 can keep up with busN
curN+=dist*speedN;
cur0=max(cur0+dist*speed[0],curN);//keep up with bus0
}
}
}
return curN;
}
void init(int _L, int N, vt<ll> T, vt<int> W, int X, int M, vt<int> S){
L=_L;
n=N;
speedN=X;
m=M;
for(int i=0;i<m;i++) pos[i]=S[i]; // vi tri m tram
for(int i=0;i<n;i++){
start[i]=T[i]; // thoi gian xuat phat
speed[i]=W[i]; // van toc
}
}
ll arrival_time(ll Y){
if(n==1) return sub1(Y);
return -1;
}
#ifdef Vhai2005
int main(){
FPTU;
#ifdef Vhai2005
freopen("sample.inp","r",stdin);
freopen("sample.out","w",stdout);
#endif
int l, _n, x, _m, q; cin >> l >> _n >> x >> _m >> q;
vector <long long> t(_n);
vector <int> w(_n);
vector <int> s(_m);
for (int i=0; i<_n; i++) cin >> t[i];
for (int i=0; i<_n; i++) cin >> w[i];
for (int i=0; i<_m; i++) cin >> s[i];
init(l, _n, t, w, x, _m, s);
while (q--) {
long long y; cin >> y;
cout << arrival_time(y) << '\n';
}
cerr << "Time elapsed: " << TIME << " s.\n";
return 0;
}
#endif
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |