# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1115572 | staszic_ojuz | Collecting Stamps 3 (JOI20_ho_t3) | C++17 | 2 ms | 8528 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;
using ll = long long;
constexpr ll INF = 1e13 + 7;
constexpr int MAXN = 203;
ll dp[MAXN][MAXN][MAXN][2];
int main()
{
int n, p;
cin >> n >> p;
vector<int> r;
vector<int> l;
vector<int> t;
r.push_back(0);
r.push_back(0);
l.push_back(0);
l.push_back(0);
t.push_back(INF);
for(int i = 0; i < n; ++i)
{
int a;
cin >> a;
r.push_back(a);
}
for(int i = n+1; i >= 2; --i)
l.push_back(p-r[i]);
for(int i = 0; i < n; ++i)
{
int a;
cin >> a;
t.push_back(a);
}
t.push_back(INF);
for(int i = 0; i <= n+1; ++i)
{
for(int j = 0; j <= n+1; ++j)
{
for(int k = 0; k <= n; ++k)
{
dp[i][j][k][0] = INF;
dp[i][j][k][1] = INF;
}
}
}
dp[1][1][0][0] = 0;
dp[1][1][0][1] = 0;
for(int i = 1; i <= n+1; ++i)
{
for(int j = 1; j <= n+1; ++j)
{
for(int k = 1; k <= n; ++k)
{
if(j+i > n+2)
break;
dp[i][j][k][0] = min(dp[i-1][j][k-1][0] + l[i]-l[i-1], dp[i-1][j][k-1][1] + l[i]+r[j]);
if(dp[i][j][k][0] > t[n-i+2])
dp[i][j][k][0] = min(dp[i-1][j][k][0] + l[i]-l[i-1], dp[i-1][j][k][1] + l[i]+r[j]);
dp[i][j][k][0] = min(dp[i][j][k][0], INF);
dp[i][j][k][1] = min(dp[i][j-1][k-1][1] + r[j]-r[j-1], dp[i][j-1][k-1][0] + l[i]+r[j]);
if(dp[i][j][k][1] > t[j-1])
dp[i][j][k][1] = min(dp[i][j-1][k][1] + r[j]-r[j-1], dp[i][j-1][k][0] + l[i]+r[j]);
dp[i][j][k][1] = min(dp[i][j][k][1], INF);
}
}
}
int odp = 0;
for(int i = 1; i <= n+1; ++i)
{
for(int j = 1; j <= n+1; ++j)
{
for(int k = 1; k <= n; ++k)
{
for(int zj = 0; zj < 2; ++zj)
{
if(dp[i][j][k][zj] < INF)
odp = max(odp, k);
}
}
}
}
cout << odp;
}
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... |