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;
#define int long long
const int MAX_N = 201;
const int INF = 1e17;
int N, L;
int dp[MAX_N][MAX_N][MAX_N];
int X[MAX_N];
int T[MAX_N];
struct Node{
int t;
int cur, other;
int has;
Node(int _t, int _cur, int _other, int _has){
t = _t;
cur = _cur;
other = _other;
has = _has;
}
bool operator<(const Node &b)const{
return t>b.t;
}
};
vector<Node> gen_neig(Node& cur){
int left, right;
left = max(cur.cur, cur.other);
right = min(cur.cur, cur.other);
//cout<<left<<" "<<right<<" "<<cur.t<<" "<<cur.has<<endl;
vector<Node> res;
if(cur.cur == left){
if(left>right){
int new_time = cur.t + ((X[(left+1LL)%L] - X[left] +L)%L);
if(new_time<=T[left]){
res.push_back(Node(new_time, left-1LL, right, cur.has +1LL));
}
else{
res.push_back(Node(new_time, left-1LL, right, cur.has));
}
}
}
if(cur.cur == right){
if(left>right){
int new_time = cur.t + X[right+1]- X[right];
if(new_time<=T[right+1]){
res.push_back(Node(new_time, right+1LL, left, cur.has +1LL));
}
else{
res.push_back(Node(new_time, right+1LL, left, cur.has));
}
}
}
////cout<<"pos L: "<<X[(left+1)%L]<<endl;
res.push_back(Node(cur.t + abs( (L - X[(left+1LL)%L])%L+ X[right]), cur.other, cur.cur, cur.has));
return res;
}
signed main(){
cin>>N>>L;
N++;
X[0] =0LL;
fill(&dp[0][0][0], (&dp[MAX_N-1][MAX_N-1][MAX_N-1])+1, INF);
T[0]= -1;
for(int i = 1; i<N; i++){
cin>>X[i];
}
for(int i = 1; i<N; i++){
cin>>T[i];
}
priority_queue<Node> pq;
pq.push(Node(0, 0, N-1, 0));
dp[0][N-1][0] = 0;
while(pq.size()>0){
auto cur = pq.top();
pq.pop();
////cout<<cur.cur<<" "<<cur.other<<" "<<cur.has<<" "<<cur.t<<endl;
if(dp[cur.cur][cur.other][cur.has] == cur.t){
//cout<<"actual"<<endl;
auto neigs = gen_neig(cur);
for(auto v: neigs){
if(dp[v.cur][v.other][v.has]> v.t){
pq.push(v);
dp[v.cur][v.other][v.has] = v.t;
}
}
}
else{
//cout<<dp[cur.cur][cur.other][cur.has]<<endl;
}
}
int best = 0LL;
for(int i = 0; i<N; i++){
for(int k = 0; k<N; k++){
for(int j = 0; j<=N; j++){
if(dp[i][k][j] <INF){
best = max(best, j);
}
}
}
}
cout<<best<<endl;
}
# | 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... |