#ifndef Nhoksocqt1
#include "overtaking.h"
#endif // Nhoksocqt1
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> pli;
template<class X, class Y>
inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
return uniform_int_distribution<int>(l, r)(rng);
}
const int MAXN = 1003;
pli sorted_timeTo[MAXN][MAXN];
ll maxPref[MAXN][MAXN], timeTo[MAXN][MAXN];
ll speed[MAXN], timeLeave[MAXN], pathLen, busnSpeed;
int staPos[MAXN];
int nArr, mArr;
ll sub1(ll Y) {
if(busnSpeed >= speed[0] || Y <= timeLeave[0])
return Y + pathLen * busnSpeed;
for (int i = 1; i < mArr; ++i) {
if(Y + busnSpeed * staPos[i] <= timeLeave[0] + speed[0] * staPos[i])
return timeLeave[0] + speed[0] * staPos[i] + busnSpeed * (staPos[mArr - 1] - staPos[i]);
}
return Y + pathLen * busnSpeed;
}
ll sub2(ll Y) {
ll res(Y + pathLen * busnSpeed);
for (int i = 0; i < nArr; ++i) {
if(timeLeave[i] < Y)
res = max(res, timeLeave[i] + speed[i] * pathLen);
}
return res;
}
ll arrival_time(ll Y) {
if(nArr == 1)
return sub1(Y);
if(mArr == 2)
return sub2(Y);
ll res(Y);
for (int i = 1; i < mArr; ++i) {
ll timeNow = res + (staPos[i] - staPos[i - 1]) * busnSpeed;
int pos = lower_bound(sorted_timeTo[i - 1], sorted_timeTo[i - 1] + nArr, pli(res, -1)) - sorted_timeTo[i - 1] - 1;
if(pos >= 0)
timeNow = max(timeNow, maxPref[i - 1][pos]);
res = timeNow;
}
return res;
}
void init(int _L, int _N, vector<ll> _T, vector<int> _W, int _X, int _M, vector<int> _S) {
pathLen = _L, nArr = _N, mArr = _M, busnSpeed = _X;
for (int i = 0; i < nArr; ++i)
speed[i] = _W[i];
for (int i = 0; i < nArr; ++i)
timeLeave[i] = _T[i];
for (int i = 0; i < mArr; ++i)
staPos[i] = _S[i];
for (int i = 0; i < nArr; ++i) {
timeTo[0][i] = timeLeave[i];
sorted_timeTo[0][i] = make_pair(timeTo[0][i], i);
}
sort(sorted_timeTo[0], sorted_timeTo[0] + nArr);
for (int j = 1; j < mArr; ++j) {
ll maxArrived(0);
int k(0);
for (int it = 0; it < nArr; ++it) {
int i(sorted_timeTo[j - 1][it].se);
while(k < nArr && sorted_timeTo[j - 1][k].fi < timeTo[j - 1][i]) {
int x(sorted_timeTo[j - 1][k++].se);
maxArrived = max(maxArrived, timeTo[j - 1][x] + (staPos[j] - staPos[j - 1]) * speed[x]);
}
timeTo[j][i] = max(maxArrived, timeTo[j - 1][i] + (staPos[j] - staPos[j - 1]) * speed[i]);
sorted_timeTo[j][i] = make_pair(timeTo[j][i], i);
}
sort(sorted_timeTo[j], sorted_timeTo[j] + nArr);
}
for (int j = 0; j + 1 < mArr; ++j) {
maxPref[j][0] = sorted_timeTo[j][0].fi + (staPos[j + 1] - staPos[j]) * speed[sorted_timeTo[j][0].se];
for (int i = 1; i < nArr; ++i)
maxPref[j][i] = max(maxPref[j][i - 1], sorted_timeTo[j][i].fi + (staPos[j + 1] - staPos[j]) * speed[sorted_timeTo[j][i].se]);
}
}
#ifdef Nhoksocqt1
int main(void) {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define TASK "overtaking"
if(fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
vector<ll> _T;
vector<int> _W, _S;
int _L, _N, _M, _X;
cin >> _L >> _N;
_T.resize(_N);
for (int i = 0; i < _N; ++i)
cin >> _T[i];
_W.resize(_N);
for (int i = 0; i < _N; ++i)
cin >> _W[i];
cin >> _X >> _M;
_S.resize(_M);
for (int i = 0; i < _M; ++i)
cin >> _S[i];
init(_L, _N, _T, _W, _X, _M, _S);
int _Q;
cin >> _Q;
for (int t = 0; t < _Q; ++t) {
ll _Y;
cin >> _Y;
cout << "ASK " << _Y << ": ";
cout << arrival_time(_Y) << '\n';
}
return 0;
}
#endif // Nhoksocqt1
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
10696 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
3 ms |
19036 KB |
Output is correct |
7 |
Correct |
4 ms |
29276 KB |
Output is correct |
8 |
Correct |
4 ms |
31320 KB |
Output is correct |
9 |
Correct |
6 ms |
31324 KB |
Output is correct |
10 |
Correct |
4 ms |
31324 KB |
Output is correct |
11 |
Correct |
4 ms |
31320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
3 ms |
4440 KB |
Output is correct |
7 |
Correct |
5 ms |
4440 KB |
Output is correct |
8 |
Correct |
4 ms |
4440 KB |
Output is correct |
9 |
Correct |
3 ms |
4444 KB |
Output is correct |
10 |
Correct |
3 ms |
4444 KB |
Output is correct |
11 |
Correct |
3 ms |
4444 KB |
Output is correct |
12 |
Correct |
3 ms |
4444 KB |
Output is correct |
13 |
Correct |
4 ms |
4564 KB |
Output is correct |
14 |
Correct |
4 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
10588 KB |
Output is correct |
5 |
Correct |
1 ms |
10696 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
10584 KB |
Output is correct |
10 |
Correct |
2 ms |
10592 KB |
Output is correct |
11 |
Correct |
2 ms |
10588 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
2 ms |
10620 KB |
Output is correct |
21 |
Correct |
2 ms |
10588 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
2 ms |
10588 KB |
Output is correct |
24 |
Correct |
2 ms |
10588 KB |
Output is correct |
25 |
Correct |
2 ms |
10588 KB |
Output is correct |
26 |
Correct |
2 ms |
10588 KB |
Output is correct |
27 |
Correct |
2 ms |
10588 KB |
Output is correct |
28 |
Correct |
2 ms |
8540 KB |
Output is correct |
29 |
Correct |
2 ms |
8540 KB |
Output is correct |
30 |
Correct |
2 ms |
8540 KB |
Output is correct |
31 |
Correct |
2 ms |
8540 KB |
Output is correct |
32 |
Correct |
2 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
10588 KB |
Output is correct |
34 |
Correct |
2 ms |
10588 KB |
Output is correct |
35 |
Correct |
2 ms |
10588 KB |
Output is correct |
36 |
Correct |
2 ms |
10588 KB |
Output is correct |
37 |
Correct |
2 ms |
10588 KB |
Output is correct |
38 |
Correct |
2 ms |
10588 KB |
Output is correct |
39 |
Correct |
2 ms |
10824 KB |
Output is correct |
40 |
Correct |
2 ms |
10696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
10588 KB |
Output is correct |
5 |
Correct |
1 ms |
10696 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
3 ms |
19036 KB |
Output is correct |
8 |
Correct |
4 ms |
29276 KB |
Output is correct |
9 |
Correct |
4 ms |
31320 KB |
Output is correct |
10 |
Correct |
6 ms |
31324 KB |
Output is correct |
11 |
Correct |
4 ms |
31324 KB |
Output is correct |
12 |
Correct |
4 ms |
31320 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
2 ms |
10584 KB |
Output is correct |
17 |
Correct |
2 ms |
10592 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
2 ms |
10588 KB |
Output is correct |
21 |
Correct |
2 ms |
10588 KB |
Output is correct |
22 |
Correct |
2 ms |
10588 KB |
Output is correct |
23 |
Correct |
2 ms |
10588 KB |
Output is correct |
24 |
Correct |
2 ms |
10588 KB |
Output is correct |
25 |
Correct |
2 ms |
10588 KB |
Output is correct |
26 |
Correct |
2 ms |
10588 KB |
Output is correct |
27 |
Correct |
2 ms |
10620 KB |
Output is correct |
28 |
Correct |
2 ms |
10588 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
2 ms |
10588 KB |
Output is correct |
31 |
Correct |
2 ms |
10588 KB |
Output is correct |
32 |
Correct |
2 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
10588 KB |
Output is correct |
34 |
Correct |
2 ms |
10588 KB |
Output is correct |
35 |
Correct |
2 ms |
8540 KB |
Output is correct |
36 |
Correct |
2 ms |
8540 KB |
Output is correct |
37 |
Correct |
2 ms |
8540 KB |
Output is correct |
38 |
Correct |
2 ms |
8540 KB |
Output is correct |
39 |
Correct |
2 ms |
10588 KB |
Output is correct |
40 |
Correct |
2 ms |
10588 KB |
Output is correct |
41 |
Correct |
2 ms |
10588 KB |
Output is correct |
42 |
Correct |
2 ms |
10588 KB |
Output is correct |
43 |
Correct |
2 ms |
10588 KB |
Output is correct |
44 |
Correct |
2 ms |
10588 KB |
Output is correct |
45 |
Correct |
2 ms |
10588 KB |
Output is correct |
46 |
Correct |
2 ms |
10824 KB |
Output is correct |
47 |
Correct |
2 ms |
10696 KB |
Output is correct |
48 |
Correct |
71 ms |
31824 KB |
Output is correct |
49 |
Correct |
163 ms |
32052 KB |
Output is correct |
50 |
Correct |
136 ms |
32048 KB |
Output is correct |
51 |
Correct |
150 ms |
31852 KB |
Output is correct |
52 |
Correct |
145 ms |
32084 KB |
Output is correct |
53 |
Correct |
125 ms |
32052 KB |
Output is correct |
54 |
Correct |
148 ms |
32080 KB |
Output is correct |
55 |
Correct |
83 ms |
31924 KB |
Output is correct |
56 |
Correct |
156 ms |
32080 KB |
Output is correct |
57 |
Correct |
142 ms |
32084 KB |
Output is correct |
58 |
Correct |
136 ms |
32056 KB |
Output is correct |
59 |
Correct |
154 ms |
32084 KB |
Output is correct |
60 |
Correct |
155 ms |
32084 KB |
Output is correct |
61 |
Correct |
157 ms |
32084 KB |
Output is correct |
62 |
Correct |
7 ms |
31580 KB |
Output is correct |
63 |
Correct |
13 ms |
4700 KB |
Output is correct |
64 |
Correct |
238 ms |
31984 KB |
Output is correct |
65 |
Correct |
171 ms |
21240 KB |
Output is correct |
66 |
Correct |
494 ms |
32080 KB |
Output is correct |
67 |
Correct |
512 ms |
32084 KB |
Output is correct |
68 |
Correct |
479 ms |
32080 KB |
Output is correct |
69 |
Correct |
232 ms |
32068 KB |
Output is correct |
70 |
Correct |
192 ms |
32052 KB |
Output is correct |
71 |
Correct |
302 ms |
32020 KB |
Output is correct |
72 |
Correct |
206 ms |
32080 KB |
Output is correct |
73 |
Correct |
297 ms |
32048 KB |
Output is correct |
74 |
Correct |
241 ms |
32056 KB |
Output is correct |
75 |
Correct |
427 ms |
32084 KB |
Output is correct |
76 |
Correct |
461 ms |
32052 KB |
Output is correct |
77 |
Correct |
490 ms |
32084 KB |
Output is correct |
78 |
Correct |
156 ms |
32028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
10588 KB |
Output is correct |
5 |
Correct |
1 ms |
10696 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
3 ms |
19036 KB |
Output is correct |
8 |
Correct |
4 ms |
29276 KB |
Output is correct |
9 |
Correct |
4 ms |
31320 KB |
Output is correct |
10 |
Correct |
6 ms |
31324 KB |
Output is correct |
11 |
Correct |
4 ms |
31324 KB |
Output is correct |
12 |
Correct |
4 ms |
31320 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
4440 KB |
Output is correct |
18 |
Correct |
3 ms |
4440 KB |
Output is correct |
19 |
Correct |
5 ms |
4440 KB |
Output is correct |
20 |
Correct |
4 ms |
4440 KB |
Output is correct |
21 |
Correct |
3 ms |
4444 KB |
Output is correct |
22 |
Correct |
3 ms |
4444 KB |
Output is correct |
23 |
Correct |
3 ms |
4444 KB |
Output is correct |
24 |
Correct |
3 ms |
4444 KB |
Output is correct |
25 |
Correct |
4 ms |
4564 KB |
Output is correct |
26 |
Correct |
4 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 ms |
10584 KB |
Output is correct |
28 |
Correct |
2 ms |
10592 KB |
Output is correct |
29 |
Correct |
2 ms |
10588 KB |
Output is correct |
30 |
Correct |
2 ms |
10588 KB |
Output is correct |
31 |
Correct |
2 ms |
10588 KB |
Output is correct |
32 |
Correct |
2 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
10588 KB |
Output is correct |
34 |
Correct |
2 ms |
10588 KB |
Output is correct |
35 |
Correct |
2 ms |
10588 KB |
Output is correct |
36 |
Correct |
2 ms |
10588 KB |
Output is correct |
37 |
Correct |
2 ms |
10588 KB |
Output is correct |
38 |
Correct |
2 ms |
10620 KB |
Output is correct |
39 |
Correct |
2 ms |
10588 KB |
Output is correct |
40 |
Correct |
1 ms |
6492 KB |
Output is correct |
41 |
Correct |
2 ms |
10588 KB |
Output is correct |
42 |
Correct |
2 ms |
10588 KB |
Output is correct |
43 |
Correct |
2 ms |
10588 KB |
Output is correct |
44 |
Correct |
2 ms |
10588 KB |
Output is correct |
45 |
Correct |
2 ms |
10588 KB |
Output is correct |
46 |
Correct |
2 ms |
8540 KB |
Output is correct |
47 |
Correct |
2 ms |
8540 KB |
Output is correct |
48 |
Correct |
2 ms |
8540 KB |
Output is correct |
49 |
Correct |
2 ms |
8540 KB |
Output is correct |
50 |
Correct |
2 ms |
10588 KB |
Output is correct |
51 |
Correct |
2 ms |
10588 KB |
Output is correct |
52 |
Correct |
2 ms |
10588 KB |
Output is correct |
53 |
Correct |
2 ms |
10588 KB |
Output is correct |
54 |
Correct |
2 ms |
10588 KB |
Output is correct |
55 |
Correct |
2 ms |
10588 KB |
Output is correct |
56 |
Correct |
2 ms |
10588 KB |
Output is correct |
57 |
Correct |
2 ms |
10824 KB |
Output is correct |
58 |
Correct |
2 ms |
10696 KB |
Output is correct |
59 |
Correct |
71 ms |
31824 KB |
Output is correct |
60 |
Correct |
163 ms |
32052 KB |
Output is correct |
61 |
Correct |
136 ms |
32048 KB |
Output is correct |
62 |
Correct |
150 ms |
31852 KB |
Output is correct |
63 |
Correct |
145 ms |
32084 KB |
Output is correct |
64 |
Correct |
125 ms |
32052 KB |
Output is correct |
65 |
Correct |
148 ms |
32080 KB |
Output is correct |
66 |
Correct |
83 ms |
31924 KB |
Output is correct |
67 |
Correct |
156 ms |
32080 KB |
Output is correct |
68 |
Correct |
142 ms |
32084 KB |
Output is correct |
69 |
Correct |
136 ms |
32056 KB |
Output is correct |
70 |
Correct |
154 ms |
32084 KB |
Output is correct |
71 |
Correct |
155 ms |
32084 KB |
Output is correct |
72 |
Correct |
157 ms |
32084 KB |
Output is correct |
73 |
Correct |
7 ms |
31580 KB |
Output is correct |
74 |
Correct |
13 ms |
4700 KB |
Output is correct |
75 |
Correct |
238 ms |
31984 KB |
Output is correct |
76 |
Correct |
171 ms |
21240 KB |
Output is correct |
77 |
Correct |
494 ms |
32080 KB |
Output is correct |
78 |
Correct |
512 ms |
32084 KB |
Output is correct |
79 |
Correct |
479 ms |
32080 KB |
Output is correct |
80 |
Correct |
232 ms |
32068 KB |
Output is correct |
81 |
Correct |
192 ms |
32052 KB |
Output is correct |
82 |
Correct |
302 ms |
32020 KB |
Output is correct |
83 |
Correct |
206 ms |
32080 KB |
Output is correct |
84 |
Correct |
297 ms |
32048 KB |
Output is correct |
85 |
Correct |
241 ms |
32056 KB |
Output is correct |
86 |
Correct |
427 ms |
32084 KB |
Output is correct |
87 |
Correct |
461 ms |
32052 KB |
Output is correct |
88 |
Correct |
490 ms |
32084 KB |
Output is correct |
89 |
Correct |
156 ms |
32028 KB |
Output is correct |
90 |
Execution timed out |
3575 ms |
34284 KB |
Time limit exceeded |
91 |
Halted |
0 ms |
0 KB |
- |