# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
364351 | Killer2501 | Collecting Stamps 3 (JOI20_ho_t3) | C++14 | 123 ms | 130796 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>
#define pb push_back
#define task "sequence"
#define pll pair<ll, ll>
#define pii pair<vector<ll>, ll>
#define fi first
#define se second
using ll = long long;
const long long mod = 1e15+7;
const ll mod1 = 1e9+1;
const ll N = 205;
const int base = 350;
using ull = unsigned long long;
using namespace std;
string s, ss;
ll n, m, t, k, T, cnt, tong, a[N], c[N], b[N], dp[N][N][N][2];
vector<ll> adj[N], kq;
pll p[N];
int ans;
void Min(ll& x, ll y)
{
if(x > y)x = y;
}
void sol()
{
cin >> n >> m;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
b[i] = m - a[i];
//cout << b[i] <<" ";
}
for(int i = 1; i <= n; i ++)b[i] = m - a[n-i+1];
//cout << '\n';
c[0] = c[n+1] = -1;
for(int i = 1; i <= n; i ++)cin >> c[i];
for(int i = 0; i <= n; i ++)
for(int j = 0; j <= n; j ++)
for(int l = 0; l <= n; l ++)dp[i][j][l][0] = dp[i][j][l][1] = mod;
dp[0][0][0][0] = dp[0][0][0][1] = 0;
for(int i = 0; i <= n; i ++)
{
for(int j = 0; j <= n-i; j ++)
{
for(int l = 0; l <= n; l ++)
{
if(dp[i][j][l][0] != mod)
{
ans = max(ans, l);
if(i < n)
{
k = dp[i][j][l][0] + a[i+1] - a[i];
Min(dp[i+1][j][l+(k<=c[i+1])][0], k);
}
if(j < n)
{
k = dp[i][j][l][0] + b[j+1] + a[i];
Min(dp[i][j+1][l+(k<=c[n-j])][1], k);
}
}
if(dp[i][j][l][1] != mod)
{
ans = max(ans, l);
if(i < n)
{
k = dp[i][j][l][1] + b[j] + a[i+1];
Min(dp[i+1][j][l+(k<=c[i+1])][0], k);
}
if(j < n)
{
k = dp[i][j][l][1] + b[j+1] - b[j];
Min(dp[i][j+1][l+(k<=c[n-j])][1], k);
}
}
// cout << i <<" "<<j<<" "<<l<<" "<<dp[i][j][l][0]<<" "<<dp[i][j][l][1] << '\n';
}
}
}
cout << ans;
}
int main()
{
if(fopen(task".in", "r")){
freopen(task".in", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ntest;
ntest = 1;
//cin >> ntest;
//cout << (1<<30) << '\n';
while(ntest -- > 0)
sol();
}
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... |