#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#include "overtaking.h"
using namespace std;
#define ll long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
ll n, x, y, m, l;
vector<ll> Ta, Wa, Sa;
vector<vector<ll> > E, TT;
vector<vector<array<ll, 2> > >Mx;
void init(int L, int N, vector<ll> t, vector<int> w, int X, int M, vector<int> s){
l=L, n=N, x=X, m=M;
for(int i=0;i<t.size();i++){
Ta.push_back(t[i]);
}
for(int i=0;i<w.size();i++){
Wa.push_back(w[i]);
}
for(int i=0;i<s.size();i++){
Sa.push_back(s[i]);
}
E.resize(n+1, vector<ll>(m+1)), TT=E;
Mx.resize(m+1, vector<array<ll, 2> >(n+1));
map<int, int>Ind;
vector<array<ll, 3> > Help_(n);
for(int i=0;i<n;i++){
TT[i][0]=Ta[i];
array<ll, 3>a={TT[i][0], i, (ll)0};
Help_[i]=a;
}
sort(all(Help_));
for(int j=1;j<m;j++){
for(int i=0;i<n;i++){
E[i][j]=TT[i][j-1]+Wa[i]*(Sa[j]-Sa[j-1]);
TT[i][j]=E[i][j];
}
ll real_mx=0, last_mx=0;
for(int i=0;i<n;i++){
if(!i || Help_[i][0]!=Help_[i-1][0])
Help_[i][2]=real_mx, last_mx=real_mx;
real_mx=max(real_mx, E[Help_[i][1]][j]);
Help_[i][2]=max(Help_[i][2], last_mx);
Ind[Help_[i][1]]=i;
}
vector<array<ll, 3> >New_(n);
for(int i=0;i<n;i++){
TT[i][j]=max(TT[i][j], Help_[Ind[i]][2]);
array<ll, 3>a={TT[i][j], i, (ll)0};
New_[i]=a;
}
ll mx=0;
for(int i=0;i<n;i++){
mx=max(mx, TT[Help_[i][1]][j]);
array<ll, 2>a={Help_[i][0], mx};
if(i && Help_[i][0]<Help_[i-1][0])
n/=0;
Mx[j-1][i]=a;
}
Help_=New_;
sort(all(Help_));
}
return;
}
ll arrival_time(ll Y){
ll y=Y;
for(int j=0;j<m-1;j++){
int l=0, r=n-1, res=-1;
while(l<=r){
int md=(l+r)/2;
if(Mx[j][md][0]>=y)
r=md-1;
else
res=md, l=md+1;
}
if(res==-1)
y+=(Sa[j+1]-Sa[j])*x;
else{
y=max(y+(Sa[j+1]-Sa[j])*x, Mx[j][res][1]);
}
}
return y;
}
//int main()
//{
// int L, N, X, M, Q;
// assert(5 == scanf("%d %d %d %d %d", &L, &N, &X, &M, &Q));
// std::vector<long long> T(N);
// for (int i = 0; i < N; i++)
// assert(1 == scanf("%lld", &T[i]));
// std::vector<int> W(N);
// for (int i = 0; i < N; i++)
// assert(1 == scanf("%d", &W[i]));
// std::vector<int> S(M);
// for (int i = 0; i < M; i++)
// assert(1 == scanf("%d", &S[i]));
// std::vector<long long> Y(Q);
// for (int i = 0; i < Q; i++)
// assert(1 == scanf("%lld", &Y[i]));
//
// fclose(stdin);
//
// init(L, N, T, W, X, M, S);
// std::vector<long long> res(Q);
// for (int i = 0; i < Q; i++)
// res[i] = arrival_time(Y[i]);
//
// for (int i = 0; i < Q; i++)
// printf("%lld\n", res[i]);
// fclose(stdout);
// return 0;
//}
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:100:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for(int i=0;i<t.size();i++){
| ~^~~~~~~~~
overtaking.cpp:103:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | for(int i=0;i<w.size();i++){
| ~^~~~~~~~~
overtaking.cpp:106:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | for(int i=0;i<s.size();i++){
| ~^~~~~~~~~
overtaking.cpp:143:18: warning: division by zero [-Wdiv-by-zero]
143 | n/=0;
| ~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
544 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
568 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 |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
776 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
1 ms |
600 KB |
Output is correct |
39 |
Correct |
1 ms |
604 KB |
Output is correct |
40 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
544 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
568 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
776 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
604 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
1 ms |
600 KB |
Output is correct |
39 |
Correct |
1 ms |
604 KB |
Output is correct |
40 |
Correct |
1 ms |
604 KB |
Output is correct |
41 |
Correct |
1 ms |
600 KB |
Output is correct |
42 |
Correct |
1 ms |
604 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
1 ms |
600 KB |
Output is correct |
46 |
Correct |
1 ms |
604 KB |
Output is correct |
47 |
Correct |
1 ms |
604 KB |
Output is correct |
48 |
Correct |
198 ms |
32016 KB |
Output is correct |
49 |
Correct |
269 ms |
32068 KB |
Output is correct |
50 |
Correct |
273 ms |
32092 KB |
Output is correct |
51 |
Correct |
270 ms |
32084 KB |
Output is correct |
52 |
Correct |
269 ms |
32084 KB |
Output is correct |
53 |
Correct |
272 ms |
32080 KB |
Output is correct |
54 |
Correct |
266 ms |
32080 KB |
Output is correct |
55 |
Correct |
208 ms |
32028 KB |
Output is correct |
56 |
Correct |
273 ms |
32080 KB |
Output is correct |
57 |
Correct |
275 ms |
32092 KB |
Output is correct |
58 |
Correct |
278 ms |
32336 KB |
Output is correct |
59 |
Correct |
280 ms |
32064 KB |
Output is correct |
60 |
Correct |
269 ms |
32092 KB |
Output is correct |
61 |
Correct |
284 ms |
32084 KB |
Output is correct |
62 |
Correct |
12 ms |
600 KB |
Output is correct |
63 |
Correct |
2 ms |
604 KB |
Output is correct |
64 |
Correct |
252 ms |
16328 KB |
Output is correct |
65 |
Correct |
225 ms |
16368 KB |
Output is correct |
66 |
Correct |
497 ms |
32068 KB |
Output is correct |
67 |
Correct |
501 ms |
32092 KB |
Output is correct |
68 |
Correct |
510 ms |
32068 KB |
Output is correct |
69 |
Correct |
365 ms |
32088 KB |
Output is correct |
70 |
Correct |
382 ms |
32096 KB |
Output is correct |
71 |
Correct |
354 ms |
32088 KB |
Output is correct |
72 |
Correct |
355 ms |
32088 KB |
Output is correct |
73 |
Correct |
358 ms |
32092 KB |
Output is correct |
74 |
Correct |
362 ms |
32092 KB |
Output is correct |
75 |
Correct |
470 ms |
32080 KB |
Output is correct |
76 |
Correct |
475 ms |
32064 KB |
Output is correct |
77 |
Correct |
482 ms |
32332 KB |
Output is correct |
78 |
Correct |
302 ms |
32068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
544 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
568 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
1 ms |
600 KB |
Output is correct |
36 |
Correct |
1 ms |
776 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
1 ms |
604 KB |
Output is correct |
39 |
Correct |
1 ms |
604 KB |
Output is correct |
40 |
Correct |
1 ms |
604 KB |
Output is correct |
41 |
Correct |
1 ms |
604 KB |
Output is correct |
42 |
Correct |
1 ms |
604 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
1 ms |
604 KB |
Output is correct |
46 |
Correct |
1 ms |
604 KB |
Output is correct |
47 |
Correct |
1 ms |
604 KB |
Output is correct |
48 |
Correct |
1 ms |
604 KB |
Output is correct |
49 |
Correct |
1 ms |
600 KB |
Output is correct |
50 |
Correct |
1 ms |
604 KB |
Output is correct |
51 |
Correct |
1 ms |
604 KB |
Output is correct |
52 |
Correct |
1 ms |
600 KB |
Output is correct |
53 |
Correct |
1 ms |
604 KB |
Output is correct |
54 |
Correct |
1 ms |
604 KB |
Output is correct |
55 |
Correct |
1 ms |
604 KB |
Output is correct |
56 |
Correct |
1 ms |
600 KB |
Output is correct |
57 |
Correct |
1 ms |
604 KB |
Output is correct |
58 |
Correct |
1 ms |
604 KB |
Output is correct |
59 |
Correct |
198 ms |
32016 KB |
Output is correct |
60 |
Correct |
269 ms |
32068 KB |
Output is correct |
61 |
Correct |
273 ms |
32092 KB |
Output is correct |
62 |
Correct |
270 ms |
32084 KB |
Output is correct |
63 |
Correct |
269 ms |
32084 KB |
Output is correct |
64 |
Correct |
272 ms |
32080 KB |
Output is correct |
65 |
Correct |
266 ms |
32080 KB |
Output is correct |
66 |
Correct |
208 ms |
32028 KB |
Output is correct |
67 |
Correct |
273 ms |
32080 KB |
Output is correct |
68 |
Correct |
275 ms |
32092 KB |
Output is correct |
69 |
Correct |
278 ms |
32336 KB |
Output is correct |
70 |
Correct |
280 ms |
32064 KB |
Output is correct |
71 |
Correct |
269 ms |
32092 KB |
Output is correct |
72 |
Correct |
284 ms |
32084 KB |
Output is correct |
73 |
Correct |
12 ms |
600 KB |
Output is correct |
74 |
Correct |
2 ms |
604 KB |
Output is correct |
75 |
Correct |
252 ms |
16328 KB |
Output is correct |
76 |
Correct |
225 ms |
16368 KB |
Output is correct |
77 |
Correct |
497 ms |
32068 KB |
Output is correct |
78 |
Correct |
501 ms |
32092 KB |
Output is correct |
79 |
Correct |
510 ms |
32068 KB |
Output is correct |
80 |
Correct |
365 ms |
32088 KB |
Output is correct |
81 |
Correct |
382 ms |
32096 KB |
Output is correct |
82 |
Correct |
354 ms |
32088 KB |
Output is correct |
83 |
Correct |
355 ms |
32088 KB |
Output is correct |
84 |
Correct |
358 ms |
32092 KB |
Output is correct |
85 |
Correct |
362 ms |
32092 KB |
Output is correct |
86 |
Correct |
470 ms |
32080 KB |
Output is correct |
87 |
Correct |
475 ms |
32064 KB |
Output is correct |
88 |
Correct |
482 ms |
32332 KB |
Output is correct |
89 |
Correct |
302 ms |
32068 KB |
Output is correct |
90 |
Execution timed out |
3531 ms |
33360 KB |
Time limit exceeded |
91 |
Halted |
0 ms |
0 KB |
- |