This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int k_N = 200 + 3;
struct Node{
int pos1, pos2;
bool which;
int cnt;
int time;
Node(){}
Node(int pos1, int pos2, bool which, int cnt, int time){
this->pos1 = pos1;
this->pos2 = pos2;
this->which = which;
this->cnt = cnt;
this->time = time;
}
friend bool operator<(const Node &lvalue, const Node &rvalue){
return lvalue.time > rvalue.time;
}
};
int n, l, x[k_N], t[k_N];
int max_t = 0;
int dist[k_N][k_N][2][k_N];
int ans = 0;
priority_queue<Node> pq;
void try_add(int pos1, int pos2, bool which, int cnt, int time){
if(dist[pos1][pos2][which][cnt] > time){
dist[pos1][pos2][which][cnt] = time;
pq.push({pos1, pos2, which, cnt, time});
}
}
void dijkstra(){
for(int pos1 = 0; pos1 <= n + 1; ++pos1)
for(int pos2 = pos1; pos2 <= n + 1; ++pos2)
for(short which = 0; which <= 1; ++which)
for(int cnt = 0; cnt <= n; ++cnt)
dist[pos1][pos2][which][cnt] = max_t;
pq.push({0, n + 1, false, 0, 0});
dist[0][n + 1][false][0] = 0;
while(!pq.empty()){
auto [pos1, pos2, which, cnt, time] = pq.top();
pq.pop();
if(time >= max_t) break;
if(dist[pos1][pos2][which][cnt] != time)
continue;
ans = max(ans, cnt);
if(pos1 + 1 == pos2) continue;
int new_pos1, new_pos2, new_which, new_cnt, new_time;
if(!which){
new_time = time + x[pos1 + 1] - x[pos1];
new_cnt = cnt + (new_time <= t[pos1 + 1]);
new_pos1 = pos1 + 1;
new_pos2 = pos2;
new_which = false;
try_add(new_pos1, new_pos2, new_which, new_cnt, new_time);
}
else{
new_time = time + x[pos2] - x[pos2 - 1];
new_cnt = cnt + (new_time <= t[pos2 - 1]);
new_pos1 = pos1;
new_pos2 = pos2 - 1;
new_which = true;
try_add(new_pos1, new_pos2, new_which, new_cnt, new_time);
}
if(!which){
new_time = time + x[pos1] + l - x[pos2 - 1];
new_cnt = cnt + (new_time <= t[pos2 - 1]);
new_pos1 = pos1;
new_pos2 = pos2 - 1;
new_which = true;
try_add(new_pos1, new_pos2, new_which, new_cnt, new_time);
}
else{
new_time = time + x[pos1 + 1] + l - x[pos2];
new_cnt = cnt + (new_time <= t[pos1 + 1]);
new_pos1 = pos1 + 1;
new_pos2 = pos2;
new_which = false;
try_add(new_pos1, new_pos2, new_which, new_cnt, new_time);
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> l;
x[0] = 0;
for(int i = 1; i <= n; ++i)
cin >> x[i];
x[n + 1] = l;
t[0] = 0;
for(int i = 1; i <= n; ++i){
cin >> t[i];
max_t = max(max_t, t[i]);
}
t[n + 1] = 0;
max_t++;
dijkstra();
//ans -= 2;
cout << ans << "\n";
}
Compilation message (stderr)
ho_t3.cpp: In function 'void dijkstra()':
ho_t3.cpp:53:14: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
auto [pos1, pos2, which, cnt, time] = pq.top();
^
# | 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... |