# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
438884 | Snowfall | Collecting Stamps 3 (JOI20_ho_t3) | C++14 | 99 ms | 104936 KiB |
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;
long long arr[205][205][205][2];
int a[205],b[205];
main()
{
int t,p;
scanf("%d%d",&t,&p);
queue<pair<int,pair<int,int> > >q;
for(int i = 1;i <= t;i++)
{
scanf("%d",&a[i]);
}
for(int i = 1;i <= t;i++)
{
scanf("%d",&b[i]);
}
for(int i = 0;i <= t;i++)
{
for(int j = 0;j <= t;j++)
{
for(int k = 0;k <= t;k++)
{
for(int l = 0;l < 2;l++)
arr[i][j][k][l]=1e18;
}
}
}
a[t+1]=p;
arr[0][0][0][0]=0;
arr[0][0][0][1]=0;
for(int i = 0;i <= t;i++)
{
for(int j = 0;j+i <= t;j++)
{
for(int k = 0;k <= i+j;k++)
{
if(arr[i][j][k][0]+a[i+1]-a[i]<=b[i+1] && i+j<=t)
{
arr[i+1][j][k+1][0]=min(arr[i+1][j][k+1][0],arr[i][j][k][0]+a[i+1]-a[i]);
}
else
{
arr[i+1][j][k][0]=min(arr[i+1][j][k][0],arr[i][j][k][0]+a[i+1]-a[i]);
}
if(arr[i][j][k][1]+a[t-j+1]-a[t-j]<=b[t-j] && i+j<=t)
{
arr[i][j+1][k+1][1]=min(arr[i][j+1][k+1][1],arr[i][j][k][1]+a[t-j+1]-a[t-j]);
}
else
{
arr[i][j+1][k][1]=min(arr[i][j+1][k][1],arr[i][j][k][1]+a[t-j+1]-a[t-j]);
}
if(arr[i][j][k][0]+a[i]+a[t-j+1]-a[t-j]<=b[t-j] && i+j<=t)
{
arr[i][j+1][k+1][1]=min(arr[i][j+1][k+1][1],arr[i][j][k][0]+a[i]+a[t-j+1]-a[t-j]);
}
else
{
arr[i][j+1][k][1]=min(arr[i][j+1][k][1],arr[i][j][k][0]+a[i]+a[t-j+1]-a[t-j]);
}
if(arr[i][j][k][1]+p-a[t-j+1]+a[i+1]<=b[i+1] && i+j<=t)
{
arr[i+1][j][k+1][0]=min(arr[i+1][j][k+1][0],arr[i][j][k][1]+p-a[t-j+1]+a[i+1]);
}
else
{
arr[i+1][j][k][0]=min(arr[i+1][j][k][0],arr[i][j][k][1]+p-a[t-j+1]+a[i+1]);
}
}
}
}
int mx=0;
for(int i = 0;i <= t;i++)
{
for(int j = 0;j+i <= t;j++)
{
for(int k = 0;k <= i+j;k++)
{
for(int l = 0;l < 2;l++)
{
if(arr[i][j][k][l]!=1e18)
mx=max(mx,k);
}
}
}
}
printf("%d",mx);
}
Compilation message (stderr)
# | 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... |