// hola soy Dember :D
// 31/03/2024
#include <bits/stdc++.h>
#include "overtaking.h"
#define ll long long
#define pll pair<ll,ll>
//#define F first
//#define S second
#define Z size()
#define pb push_back
#define bp pop_back
#define fo(x,y,z) for(ll x=y; x<=z; x++)
#define of(x,y,z) for(ll x=y; x>=z; x--)
#define all(n) n.begin(), n.end()
#define arr(x,y,z) x+y, x+y+z
using namespace std;
const int MN=1e3+3;
ll n, m, xd, zd, ans, l, r;
ll a[MN], b[MN][MN], f[MN][MN], g[MN][MN], t[MN], w[MN], s[MN];
void init(int L, int N, vector<ll> T, vector<int> W, int X, int M, vector<int> S){
n=N; m=M;
fo(i,0,n-1)a[i]=i, f[i][0]=t[i]=T[i], w[i]=W[i];w[n]=X;
fo(i,0,m-1)s[i]=S[i];
fo(j,1,m-1){
sort(arr(a,0,n), [&] (const int &x, const int &y){
if(f[x][j-1]!=f[y][j-1])return f[x][j-1]<f[y][j-1];
return w[x]<w[y];
});
xd=0;
fo(h,0,n-1){
ll i=a[h];
f[i][j]=max(xd, f[i][j-1]+w[i]*(s[j]-s[j-1]));
xd=f[i][j];
}
}
fo(j,1,m-1){
sort(arr(a,0,n), [&] (const int &x, const int &y){
if(f[x][j-1]!=f[y][j-1])return f[x][j-1]<f[y][j-1];
return w[x]<w[y];
});
fo(h,0,n-1){
ll i=a[h];
g[j][h]=f[i][j];
if(h)g[j][h]=max(g[j][h], g[j][h-1]);
}
fo(i,0,n-1)b[i][j]=a[i];
}
return;
}
ll arrival_time(long long Y) {
ans=Y;
fo(j,1,m-1){
l=0, r=n-1, zd=-1;
while (l <= r) {
xd=(l+r)/2;
if (ans>f[b[xd][j]][j-1])zd=xd,l=xd+1;
else r=xd-1;
}
xd=ans+w[n]*(s[j]-s[j-1]);
if(zd!=-1)xd=max(xd, g[j][zd]);
ans=xd;
//cout<<ans<<" ";
}
return ans;
}
Compilation message
overtaking.cpp: In function 'void init(int, int, std::vector<long long int>, std::vector<int>, int, int, std::vector<int>)':
overtaking.cpp:14:19: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
14 | #define fo(x,y,z) for(ll x=y; x<=z; x++)
| ^~~
overtaking.cpp:29:5: note: in expansion of macro 'fo'
29 | fo(i,0,n-1)a[i]=i, f[i][0]=t[i]=T[i], w[i]=W[i];w[n]=X;
| ^~
overtaking.cpp:29:53: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
29 | fo(i,0,n-1)a[i]=i, f[i][0]=t[i]=T[i], w[i]=W[i];w[n]=X;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
6576 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
3 ms |
8768 KB |
Output is correct |
7 |
Correct |
5 ms |
10704 KB |
Output is correct |
8 |
Correct |
4 ms |
10588 KB |
Output is correct |
9 |
Correct |
4 ms |
10804 KB |
Output is correct |
10 |
Correct |
4 ms |
10588 KB |
Output is correct |
11 |
Correct |
4 ms |
10816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
12632 KB |
Output is correct |
6 |
Correct |
3 ms |
16732 KB |
Output is correct |
7 |
Correct |
3 ms |
17244 KB |
Output is correct |
8 |
Correct |
3 ms |
17244 KB |
Output is correct |
9 |
Correct |
3 ms |
17244 KB |
Output is correct |
10 |
Correct |
3 ms |
17244 KB |
Output is correct |
11 |
Correct |
3 ms |
17244 KB |
Output is correct |
12 |
Correct |
3 ms |
17244 KB |
Output is correct |
13 |
Correct |
3 ms |
17240 KB |
Output is correct |
14 |
Correct |
3 ms |
17244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
6576 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6744 KB |
Output is correct |
7 |
Correct |
1 ms |
6488 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8740 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
2 ms |
8540 KB |
Output is correct |
15 |
Correct |
2 ms |
8536 KB |
Output is correct |
16 |
Correct |
2 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
18 |
Correct |
2 ms |
8540 KB |
Output is correct |
19 |
Correct |
2 ms |
8540 KB |
Output is correct |
20 |
Correct |
2 ms |
8792 KB |
Output is correct |
21 |
Correct |
2 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
8540 KB |
Output is correct |
23 |
Correct |
2 ms |
8540 KB |
Output is correct |
24 |
Correct |
2 ms |
8540 KB |
Output is correct |
25 |
Correct |
2 ms |
8540 KB |
Output is correct |
26 |
Correct |
2 ms |
8540 KB |
Output is correct |
27 |
Correct |
2 ms |
8540 KB |
Output is correct |
28 |
Correct |
2 ms |
8540 KB |
Output is correct |
29 |
Correct |
1 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 |
8536 KB |
Output is correct |
33 |
Correct |
2 ms |
8540 KB |
Output is correct |
34 |
Correct |
2 ms |
8540 KB |
Output is correct |
35 |
Correct |
2 ms |
8540 KB |
Output is correct |
36 |
Correct |
1 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 |
8540 KB |
Output is correct |
40 |
Correct |
2 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
6576 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
3 ms |
8768 KB |
Output is correct |
8 |
Correct |
5 ms |
10704 KB |
Output is correct |
9 |
Correct |
4 ms |
10588 KB |
Output is correct |
10 |
Correct |
4 ms |
10804 KB |
Output is correct |
11 |
Correct |
4 ms |
10588 KB |
Output is correct |
12 |
Correct |
4 ms |
10816 KB |
Output is correct |
13 |
Correct |
1 ms |
6744 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6488 KB |
Output is correct |
16 |
Correct |
2 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
18 |
Correct |
1 ms |
8540 KB |
Output is correct |
19 |
Correct |
2 ms |
8740 KB |
Output is correct |
20 |
Correct |
2 ms |
8540 KB |
Output is correct |
21 |
Correct |
2 ms |
8540 KB |
Output is correct |
22 |
Correct |
2 ms |
8536 KB |
Output is correct |
23 |
Correct |
2 ms |
8540 KB |
Output is correct |
24 |
Correct |
2 ms |
8540 KB |
Output is correct |
25 |
Correct |
2 ms |
8540 KB |
Output is correct |
26 |
Correct |
2 ms |
8540 KB |
Output is correct |
27 |
Correct |
2 ms |
8792 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 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 |
8540 KB |
Output is correct |
33 |
Correct |
2 ms |
8540 KB |
Output is correct |
34 |
Correct |
2 ms |
8540 KB |
Output is correct |
35 |
Correct |
2 ms |
8540 KB |
Output is correct |
36 |
Correct |
1 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 |
8536 KB |
Output is correct |
40 |
Correct |
2 ms |
8540 KB |
Output is correct |
41 |
Correct |
2 ms |
8540 KB |
Output is correct |
42 |
Correct |
2 ms |
8540 KB |
Output is correct |
43 |
Correct |
1 ms |
8540 KB |
Output is correct |
44 |
Correct |
2 ms |
8540 KB |
Output is correct |
45 |
Correct |
2 ms |
8540 KB |
Output is correct |
46 |
Correct |
2 ms |
8540 KB |
Output is correct |
47 |
Correct |
2 ms |
8540 KB |
Output is correct |
48 |
Correct |
74 ms |
23900 KB |
Output is correct |
49 |
Correct |
127 ms |
24204 KB |
Output is correct |
50 |
Correct |
122 ms |
24156 KB |
Output is correct |
51 |
Correct |
125 ms |
24404 KB |
Output is correct |
52 |
Correct |
138 ms |
24216 KB |
Output is correct |
53 |
Correct |
124 ms |
24144 KB |
Output is correct |
54 |
Correct |
126 ms |
24152 KB |
Output is correct |
55 |
Correct |
88 ms |
24100 KB |
Output is correct |
56 |
Correct |
144 ms |
24204 KB |
Output is correct |
57 |
Correct |
131 ms |
24144 KB |
Output is correct |
58 |
Correct |
138 ms |
24040 KB |
Output is correct |
59 |
Correct |
154 ms |
24200 KB |
Output is correct |
60 |
Correct |
146 ms |
24204 KB |
Output is correct |
61 |
Correct |
129 ms |
24144 KB |
Output is correct |
62 |
Correct |
14 ms |
10840 KB |
Output is correct |
63 |
Correct |
5 ms |
17496 KB |
Output is correct |
64 |
Correct |
213 ms |
19032 KB |
Output is correct |
65 |
Correct |
183 ms |
22144 KB |
Output is correct |
66 |
Correct |
441 ms |
24236 KB |
Output is correct |
67 |
Correct |
472 ms |
24152 KB |
Output is correct |
68 |
Correct |
474 ms |
24228 KB |
Output is correct |
69 |
Correct |
168 ms |
24204 KB |
Output is correct |
70 |
Correct |
160 ms |
24200 KB |
Output is correct |
71 |
Correct |
139 ms |
24148 KB |
Output is correct |
72 |
Correct |
144 ms |
24184 KB |
Output is correct |
73 |
Correct |
138 ms |
24156 KB |
Output is correct |
74 |
Correct |
146 ms |
24144 KB |
Output is correct |
75 |
Correct |
405 ms |
24208 KB |
Output is correct |
76 |
Correct |
429 ms |
24208 KB |
Output is correct |
77 |
Correct |
433 ms |
24404 KB |
Output is correct |
78 |
Correct |
111 ms |
24172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
6576 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
3 ms |
8768 KB |
Output is correct |
8 |
Correct |
5 ms |
10704 KB |
Output is correct |
9 |
Correct |
4 ms |
10588 KB |
Output is correct |
10 |
Correct |
4 ms |
10804 KB |
Output is correct |
11 |
Correct |
4 ms |
10588 KB |
Output is correct |
12 |
Correct |
4 ms |
10816 KB |
Output is correct |
13 |
Correct |
1 ms |
6744 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6488 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
2 ms |
12632 KB |
Output is correct |
18 |
Correct |
3 ms |
16732 KB |
Output is correct |
19 |
Correct |
3 ms |
17244 KB |
Output is correct |
20 |
Correct |
3 ms |
17244 KB |
Output is correct |
21 |
Correct |
3 ms |
17244 KB |
Output is correct |
22 |
Correct |
3 ms |
17244 KB |
Output is correct |
23 |
Correct |
3 ms |
17244 KB |
Output is correct |
24 |
Correct |
3 ms |
17244 KB |
Output is correct |
25 |
Correct |
3 ms |
17240 KB |
Output is correct |
26 |
Correct |
3 ms |
17244 KB |
Output is correct |
27 |
Correct |
2 ms |
8540 KB |
Output is correct |
28 |
Correct |
2 ms |
8540 KB |
Output is correct |
29 |
Correct |
1 ms |
8540 KB |
Output is correct |
30 |
Correct |
2 ms |
8740 KB |
Output is correct |
31 |
Correct |
2 ms |
8540 KB |
Output is correct |
32 |
Correct |
2 ms |
8540 KB |
Output is correct |
33 |
Correct |
2 ms |
8536 KB |
Output is correct |
34 |
Correct |
2 ms |
8540 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 |
8792 KB |
Output is correct |
39 |
Correct |
2 ms |
6492 KB |
Output is correct |
40 |
Correct |
2 ms |
8540 KB |
Output is correct |
41 |
Correct |
2 ms |
8540 KB |
Output is correct |
42 |
Correct |
2 ms |
8540 KB |
Output is correct |
43 |
Correct |
2 ms |
8540 KB |
Output is correct |
44 |
Correct |
2 ms |
8540 KB |
Output is correct |
45 |
Correct |
2 ms |
8540 KB |
Output is correct |
46 |
Correct |
2 ms |
8540 KB |
Output is correct |
47 |
Correct |
1 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 |
8536 KB |
Output is correct |
51 |
Correct |
2 ms |
8540 KB |
Output is correct |
52 |
Correct |
2 ms |
8540 KB |
Output is correct |
53 |
Correct |
2 ms |
8540 KB |
Output is correct |
54 |
Correct |
1 ms |
8540 KB |
Output is correct |
55 |
Correct |
2 ms |
8540 KB |
Output is correct |
56 |
Correct |
2 ms |
8540 KB |
Output is correct |
57 |
Correct |
2 ms |
8540 KB |
Output is correct |
58 |
Correct |
2 ms |
8540 KB |
Output is correct |
59 |
Correct |
74 ms |
23900 KB |
Output is correct |
60 |
Correct |
127 ms |
24204 KB |
Output is correct |
61 |
Correct |
122 ms |
24156 KB |
Output is correct |
62 |
Correct |
125 ms |
24404 KB |
Output is correct |
63 |
Correct |
138 ms |
24216 KB |
Output is correct |
64 |
Correct |
124 ms |
24144 KB |
Output is correct |
65 |
Correct |
126 ms |
24152 KB |
Output is correct |
66 |
Correct |
88 ms |
24100 KB |
Output is correct |
67 |
Correct |
144 ms |
24204 KB |
Output is correct |
68 |
Correct |
131 ms |
24144 KB |
Output is correct |
69 |
Correct |
138 ms |
24040 KB |
Output is correct |
70 |
Correct |
154 ms |
24200 KB |
Output is correct |
71 |
Correct |
146 ms |
24204 KB |
Output is correct |
72 |
Correct |
129 ms |
24144 KB |
Output is correct |
73 |
Correct |
14 ms |
10840 KB |
Output is correct |
74 |
Correct |
5 ms |
17496 KB |
Output is correct |
75 |
Correct |
213 ms |
19032 KB |
Output is correct |
76 |
Correct |
183 ms |
22144 KB |
Output is correct |
77 |
Correct |
441 ms |
24236 KB |
Output is correct |
78 |
Correct |
472 ms |
24152 KB |
Output is correct |
79 |
Correct |
474 ms |
24228 KB |
Output is correct |
80 |
Correct |
168 ms |
24204 KB |
Output is correct |
81 |
Correct |
160 ms |
24200 KB |
Output is correct |
82 |
Correct |
139 ms |
24148 KB |
Output is correct |
83 |
Correct |
144 ms |
24184 KB |
Output is correct |
84 |
Correct |
138 ms |
24156 KB |
Output is correct |
85 |
Correct |
146 ms |
24144 KB |
Output is correct |
86 |
Correct |
405 ms |
24208 KB |
Output is correct |
87 |
Correct |
429 ms |
24208 KB |
Output is correct |
88 |
Correct |
433 ms |
24404 KB |
Output is correct |
89 |
Correct |
111 ms |
24172 KB |
Output is correct |
90 |
Execution timed out |
3514 ms |
26452 KB |
Time limit exceeded |
91 |
Halted |
0 ms |
0 KB |
- |