Submission #331436

#TimeUsernameProblemLanguageResultExecution timeMemory
331436syyCollecting Stamps 3 (JOI20_ho_t3)C++17
100 / 100
367 ms135424 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<ll, pi> ipi;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define size(v) (ll) v.size()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (ll) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

ll n, l, x[205], t[205], num[2][205], ans, memo[205][205][2][205];

ll dp(ll i, ll j, bool k, ll s) {
	//visited first i ACW, first j CW, now at (k ? CW : ACW), having taken s stamps
	//returns minimum time taken
	if (i < 0 or j < 0) return LLINF;
	if (i == 0 and j == 0) return (s == 0 ? 0 : LLINF);
	if (i == 0) {
		if (!k) return (num[0][j] >= s ? x[j] : LLINF);
		else return (num[0][j] >= s ? 2*x[j] : LLINF);
	}
	if (j == 0) {
		if (k) return (num[1][i] >= s ? (l-x[n-i+1]) : LLINF);
		else return (num[1][i] >= s ? 2 * (l-x[n-i+1]) : LLINF);
	}
	if (memo[i][j][k][s] != -1) return memo[i][j][k][s];
	ll res = LLINF;
	if (!k) {
		res = min({res, dp(i, j-1, k, s) + x[j] - x[j-1], dp(i, j-1, !k, s) + x[j] + (l-x[n-i+1])});
		if (s) {
			ll y = min(dp(i, j-1, k, s-1) + x[j] - x[j-1], dp(i, j-1, !k, s-1) + x[j] + (l-x[n-i+1]));
			//~ if (i == 1 and j == 3 and s == 4) cout << "hi " << y << "\n";
			if (y <= t[j]) res = min(res, y);
		}
	} else {
		res = min({res, dp(i-1, j, k, s) + x[n-i+2] - x[n-i+1], dp(i-1, j, !k, s) + x[j] + (l-x[n-i+1])});
		if (s) {
			ll y = min(dp(i-1, j, k, s-1) + x[n-i+2] - x[n-i+1], dp(i-1, j, !k, s-1) + x[j] + (l-x[n-i+1]));
			if (y <= t[n-i+1]) res = min(res, y);
		}
	}
	return memo[i][j][k][s] = res;
}

int main() {
	fastio; cin >> n >> l;
	FOR(i, 1, n) cin >> x[i];
	FOR(i, 1, n) cin >> t[i];
	FOR(i, 1, n) num[0][i] = num[0][i-1] + (x[i] <= t[i]);
	FOR(i, 1, n) num[1][i] = num[1][i-1] + ((l-x[n-i+1]) <= t[n-i+1]);
	x[0] = 0, x[n+1] = l;
	memset(memo, -1, sizeof memo);
	//~ cout << dp(1, 3, 0, 4) << "\n";
	//~ FOR(i, 0, n) FOR(j, 0, n-i) FOR(k, 0, 1) FOR(m, 0, n) printf("%lld %lld %lld %lld: %lld\n", i, j, k, m, dp(i, j, k, m));
	FOR(i, 0, n) FOR(j, 0, n-i) FOR(k, 1, n) if (min(dp(i, j, 0, k), dp(i, j, 1, k)) < (ll) 2e12) ans = max(ans, k);
	cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...