#include "overtaking.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#ifdef LOCAL
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
const int MAXN = 1005;
const int inf=1000000500ll;
const long long oo =1000000000000000500ll;
const int MOD = (int)1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> pi;
int T[MAXN][MAXN];
int n;
int m;
int xt;
vector<int32_t>S;
vector<pi> nxt[MAXN]; // nxt[t] -> {time at this station, time at next station}
void init(int32_t L, int32_t n, std::vector<long long> tt, std::vector<int32_t> W, int32_t X, int32_t m, std::vector<int32_t> S)
{
::S=S;
xt=X;
::n=n;
::m=m;
// compute arrival times of each bus at each station
for(int x=0;x<n;x++){
T[x][0]=tt[x];
}
for(int t=1;t<m;t++){
vector<pi> vec;
for(int x=0;x<n;x++){
vec.push_back({T[x][t-1],x});
}
sort(vec.begin(),vec.end());
int idx=0;
int mx=0;
for(int x=0;x<n;x++){
int xidx=vec[x].second;
while(idx<n && vec[idx].first<T[xidx][t-1]){
int idxidx=vec[idx].second;
int exp=T[idxidx][t-1] + (int)W[idxidx] * (int)(S[t]-S[t-1]);
mx=max(mx,exp);
++idx;
}
int ex=T[xidx][t-1] + (int)W[xidx] * (int)(S[t]-S[t-1]);
T[xidx][t]=max(mx,ex);
}
}
for(int t=0;t<m-1;t++){
for(int x=0;x<n;x++){
nxt[t].push_back({T[x][t],T[x][t+1]});
}
sort(nxt[t].begin(),nxt[t].end(),[](pi x, pi y){
if(x.first != y.first)return x.first <y.first;
else return x.second>y.second;//we only want to keep the biggest next of the same timing
});
bool need[n+5];memset(need,0,sizeof need);
int mx=-oo;
for(int x=0;x<n;x++){
if(nxt[t][x].second > mx){
mx=nxt[t][x].second;
need[x]=1;
}
}
vector<pi>res;
for(int x=0;x<n;x++){
if(need[x])res.push_back(nxt[t][x]);
}
nxt[t]=res;
}
}
long long arrival_time(long long Y)
{
for(int t=1;t<m;t++){
int exp=Y + xt * (int)(S[t]-S[t-1]);
auto it=lower_bound(nxt[t-1].begin(),nxt[t-1].end(),make_pair(Y,-oo));
if(it != nxt[t-1].begin()){
exp=max(exp,prev(it)->second);
}
Y=exp;
}
return Y;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
564 KB |
Output is correct |
9 |
Correct |
4 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
500 KB |
Output is correct |
11 |
Correct |
3 ms |
488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
7516 KB |
Output is correct |
8 |
Correct |
2 ms |
7516 KB |
Output is correct |
9 |
Correct |
2 ms |
7516 KB |
Output is correct |
10 |
Correct |
2 ms |
7396 KB |
Output is correct |
11 |
Correct |
3 ms |
7516 KB |
Output is correct |
12 |
Correct |
2 ms |
7516 KB |
Output is correct |
13 |
Correct |
2 ms |
7516 KB |
Output is correct |
14 |
Correct |
2 ms |
7512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2904 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
2 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2696 KB |
Output is correct |
17 |
Correct |
2 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
2 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
2 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
2 ms |
2648 KB |
Output is correct |
25 |
Correct |
2 ms |
2648 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
1 ms |
2524 KB |
Output is correct |
32 |
Correct |
1 ms |
2652 KB |
Output is correct |
33 |
Correct |
1 ms |
2648 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
2 ms |
2652 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
39 |
Correct |
2 ms |
2752 KB |
Output is correct |
40 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
564 KB |
Output is correct |
10 |
Correct |
4 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
500 KB |
Output is correct |
12 |
Correct |
3 ms |
488 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2904 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
2 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2696 KB |
Output is correct |
24 |
Correct |
2 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2648 KB |
Output is correct |
32 |
Correct |
2 ms |
2648 KB |
Output is correct |
33 |
Correct |
1 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2652 KB |
Output is correct |
38 |
Correct |
1 ms |
2524 KB |
Output is correct |
39 |
Correct |
1 ms |
2652 KB |
Output is correct |
40 |
Correct |
1 ms |
2648 KB |
Output is correct |
41 |
Correct |
1 ms |
2652 KB |
Output is correct |
42 |
Correct |
1 ms |
2652 KB |
Output is correct |
43 |
Correct |
1 ms |
2652 KB |
Output is correct |
44 |
Correct |
2 ms |
2652 KB |
Output is correct |
45 |
Correct |
2 ms |
2652 KB |
Output is correct |
46 |
Correct |
2 ms |
2752 KB |
Output is correct |
47 |
Correct |
2 ms |
2652 KB |
Output is correct |
48 |
Correct |
153 ms |
24428 KB |
Output is correct |
49 |
Correct |
297 ms |
24540 KB |
Output is correct |
50 |
Correct |
263 ms |
24404 KB |
Output is correct |
51 |
Correct |
258 ms |
24660 KB |
Output is correct |
52 |
Correct |
275 ms |
24400 KB |
Output is correct |
53 |
Correct |
260 ms |
24400 KB |
Output is correct |
54 |
Correct |
285 ms |
24560 KB |
Output is correct |
55 |
Correct |
156 ms |
24268 KB |
Output is correct |
56 |
Correct |
259 ms |
24568 KB |
Output is correct |
57 |
Correct |
226 ms |
24748 KB |
Output is correct |
58 |
Correct |
245 ms |
24536 KB |
Output is correct |
59 |
Correct |
254 ms |
24400 KB |
Output is correct |
60 |
Correct |
252 ms |
24520 KB |
Output is correct |
61 |
Correct |
247 ms |
24404 KB |
Output is correct |
62 |
Correct |
14 ms |
588 KB |
Output is correct |
63 |
Correct |
3 ms |
7512 KB |
Output is correct |
64 |
Correct |
259 ms |
12884 KB |
Output is correct |
65 |
Correct |
203 ms |
16508 KB |
Output is correct |
66 |
Correct |
430 ms |
24536 KB |
Output is correct |
67 |
Correct |
433 ms |
24636 KB |
Output is correct |
68 |
Correct |
431 ms |
24556 KB |
Output is correct |
69 |
Correct |
269 ms |
24404 KB |
Output is correct |
70 |
Correct |
276 ms |
24612 KB |
Output is correct |
71 |
Correct |
307 ms |
24356 KB |
Output is correct |
72 |
Correct |
299 ms |
24656 KB |
Output is correct |
73 |
Correct |
274 ms |
24368 KB |
Output is correct |
74 |
Correct |
264 ms |
24536 KB |
Output is correct |
75 |
Correct |
414 ms |
24404 KB |
Output is correct |
76 |
Correct |
428 ms |
24668 KB |
Output is correct |
77 |
Correct |
421 ms |
24360 KB |
Output is correct |
78 |
Correct |
216 ms |
24336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
564 KB |
Output is correct |
10 |
Correct |
4 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
500 KB |
Output is correct |
12 |
Correct |
3 ms |
488 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
4700 KB |
Output is correct |
18 |
Correct |
1 ms |
6748 KB |
Output is correct |
19 |
Correct |
2 ms |
7516 KB |
Output is correct |
20 |
Correct |
2 ms |
7516 KB |
Output is correct |
21 |
Correct |
2 ms |
7516 KB |
Output is correct |
22 |
Correct |
2 ms |
7396 KB |
Output is correct |
23 |
Correct |
3 ms |
7516 KB |
Output is correct |
24 |
Correct |
2 ms |
7516 KB |
Output is correct |
25 |
Correct |
2 ms |
7516 KB |
Output is correct |
26 |
Correct |
2 ms |
7512 KB |
Output is correct |
27 |
Correct |
2 ms |
2648 KB |
Output is correct |
28 |
Correct |
1 ms |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
1 ms |
2904 KB |
Output is correct |
32 |
Correct |
1 ms |
2652 KB |
Output is correct |
33 |
Correct |
2 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
2696 KB |
Output is correct |
35 |
Correct |
2 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
2 ms |
2652 KB |
Output is correct |
38 |
Correct |
1 ms |
2652 KB |
Output is correct |
39 |
Correct |
2 ms |
2652 KB |
Output is correct |
40 |
Correct |
1 ms |
2652 KB |
Output is correct |
41 |
Correct |
1 ms |
2652 KB |
Output is correct |
42 |
Correct |
2 ms |
2648 KB |
Output is correct |
43 |
Correct |
2 ms |
2648 KB |
Output is correct |
44 |
Correct |
1 ms |
2652 KB |
Output is correct |
45 |
Correct |
1 ms |
2652 KB |
Output is correct |
46 |
Correct |
1 ms |
2652 KB |
Output is correct |
47 |
Correct |
1 ms |
2652 KB |
Output is correct |
48 |
Correct |
1 ms |
2652 KB |
Output is correct |
49 |
Correct |
1 ms |
2524 KB |
Output is correct |
50 |
Correct |
1 ms |
2652 KB |
Output is correct |
51 |
Correct |
1 ms |
2648 KB |
Output is correct |
52 |
Correct |
1 ms |
2652 KB |
Output is correct |
53 |
Correct |
1 ms |
2652 KB |
Output is correct |
54 |
Correct |
1 ms |
2652 KB |
Output is correct |
55 |
Correct |
2 ms |
2652 KB |
Output is correct |
56 |
Correct |
2 ms |
2652 KB |
Output is correct |
57 |
Correct |
2 ms |
2752 KB |
Output is correct |
58 |
Correct |
2 ms |
2652 KB |
Output is correct |
59 |
Correct |
153 ms |
24428 KB |
Output is correct |
60 |
Correct |
297 ms |
24540 KB |
Output is correct |
61 |
Correct |
263 ms |
24404 KB |
Output is correct |
62 |
Correct |
258 ms |
24660 KB |
Output is correct |
63 |
Correct |
275 ms |
24400 KB |
Output is correct |
64 |
Correct |
260 ms |
24400 KB |
Output is correct |
65 |
Correct |
285 ms |
24560 KB |
Output is correct |
66 |
Correct |
156 ms |
24268 KB |
Output is correct |
67 |
Correct |
259 ms |
24568 KB |
Output is correct |
68 |
Correct |
226 ms |
24748 KB |
Output is correct |
69 |
Correct |
245 ms |
24536 KB |
Output is correct |
70 |
Correct |
254 ms |
24400 KB |
Output is correct |
71 |
Correct |
252 ms |
24520 KB |
Output is correct |
72 |
Correct |
247 ms |
24404 KB |
Output is correct |
73 |
Correct |
14 ms |
588 KB |
Output is correct |
74 |
Correct |
3 ms |
7512 KB |
Output is correct |
75 |
Correct |
259 ms |
12884 KB |
Output is correct |
76 |
Correct |
203 ms |
16508 KB |
Output is correct |
77 |
Correct |
430 ms |
24536 KB |
Output is correct |
78 |
Correct |
433 ms |
24636 KB |
Output is correct |
79 |
Correct |
431 ms |
24556 KB |
Output is correct |
80 |
Correct |
269 ms |
24404 KB |
Output is correct |
81 |
Correct |
276 ms |
24612 KB |
Output is correct |
82 |
Correct |
307 ms |
24356 KB |
Output is correct |
83 |
Correct |
299 ms |
24656 KB |
Output is correct |
84 |
Correct |
274 ms |
24368 KB |
Output is correct |
85 |
Correct |
264 ms |
24536 KB |
Output is correct |
86 |
Correct |
414 ms |
24404 KB |
Output is correct |
87 |
Correct |
428 ms |
24668 KB |
Output is correct |
88 |
Correct |
421 ms |
24360 KB |
Output is correct |
89 |
Correct |
216 ms |
24336 KB |
Output is correct |
90 |
Execution timed out |
3558 ms |
26696 KB |
Time limit exceeded |
91 |
Halted |
0 ms |
0 KB |
- |