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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";
#define ld long double
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const deque<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
const int N=205,oo=INT_MAX/2;
int dp[N][N][N][2],n,l,x[N+2],t[N+2];
int getDist(int a,int b){
return min(abs(x[a]-x[b]),l-abs(x[a]-x[b]));
}
void input(){
scanf("%i %i",&n,&l);
for(int i=1;i<=n;i++)
scanf("%i",&x[i]);
for(int i=1;i<=n;i++)
scanf("%i",&t[i]);
}
int solve(){
for(int i=0;i<N;i++)for(int j=0;j<N;j++)for(int k=0;k<N;k++)dp[i][j][k][0]=dp[i][j][k][1]=oo;
dp[0][0][0][0]=dp[0][0][0][1]=0;
int sol=0;
for(int i=0;i<=n;i++){
for(int j=0;j<=n-i;j++){
for(int k=0;k<=n;k++){
for(int o=0;o<2;o++){
if(i+j>n||k>i+j||(i==0&&j==0)||(o==0&&i==0)||(o==1&&j==0))
continue;
if(o==0){ //left
int time0,time1,time;
if(k){
time0=dp[i-1][j][k-1][0]+getDist(n-i+2,n-i+1),time1=dp[i-1][j][k-1][1]+getDist(j,n-i+1); //Uzmi trenutni
time=min(time0,time1);
if(time<=t[n-i+1])
dp[i][j][k][o]=time;
}
time0=dp[i-1][j][k][0]+getDist(n-i+2,n-i+1),time1=dp[i-1][j][k][1]+getDist(j,n-i+1); //Nemoj uzeti trenuti
time=min(time0,time1);
dp[i][j][k][o]=min(dp[i][j][k][o],time);
}
else{ //right
int time0,time1,time;
if(k){
time0=dp[i][j-1][k-1][0]+getDist(n-i+1,j),time1=dp[i][j-1][k-1][1]+getDist(j-1,j); //Uzmi trenutni
time=min(time0,time1);
if(time<=t[j])
dp[i][j][k][o]=time;
}
time0=dp[i][j-1][k][0]+getDist(n-i+1,j),time1=dp[i][j-1][k][1]+getDist(j-1,j); //Nemoj uzeti trenuti
time=min(time0,time1);
dp[i][j][k][o]=min(dp[i][j][k][o],time);
}
if(dp[i][j][k][o]<oo)
sol=max(sol,k);
}
}
}
}
return sol;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
input();
printf("%i\n",solve());
return 0;
}
Compilation message (stderr)
ho_t3.cpp: In function 'void input()':
ho_t3.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i %i",&n,&l);
~~~~~^~~~~~~~~~~~~~~
ho_t3.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&x[i]);
~~~~~^~~~~~~~~~~~
ho_t3.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&t[i]);
~~~~~^~~~~~~~~~~~
# | 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... |