# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1152907 | AgentPengin | Collecting Stamps 3 (JOI20_ho_t3) | C++20 | 92 ms | 135292 KiB |
/**
* author: AgentPengin ( Độc cô cầu bại )
* created: 23.12.2022 10:08:02
* too lazy to update time
**/
#include<bits/stdc++.h>
#define EL '\n'
#define fi first
#define se second
#define NAME "TASK"
#define ll long long
#define lcm(a,b) (a/gcd(a,b))*b
#define db(val) "["#val" = " << (val) << "] "
#define bend(v) (v).begin(),(v).end()
#define sz(v) (int)(v).size()
#define ex exit(0)
#define int ll
using namespace std;
const ll mod = 1e9 + 7;
const int inf = 0x1FFFFFFF;
const int MAXN = 205;
int n, L, x[MAXN], t[MAXN];
int dp[MAXN][MAXN][MAXN][2];
void ckmin(int &a, int b) {
a = min(a, b);
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
if (ifstream(NAME".inp")) {
freopen(NAME".inp","r",stdin);
freopen(NAME".out","w",stdout);
}
cin >> n >> L;
memset(dp, 0x3f, sizeof dp);
for (int i = 1;i <= n;i++) {
cin >> x[i];
}
for (int i = 1;i <= n;i++) {
cin >> t[i];
}
x[n + 1] = L;
dp[0][n + 1][0][0] = dp[0][n + 1][0][1] = 0;
for (int i = 0;i <= n;i++) {
for (int j = n + 1;j > i;j--) {
for (int score = 0; score <= (i + (n - j + 1)); score++) {
if (dp[i][j][score][1] < 1e18) {
if (j - 1 > i) {
int time = dp[i][j][score][1] + (x[j] - x[j - 1]);
ckmin(dp[i][j - 1][score + (time <= t[j - 1])][1], time);
}
if (i + 1 < j) {
int time = dp[i][j][score][1] + (L - x[j] + x[i + 1]);
ckmin(dp[i + 1][j][score + (time <= t[i + 1])][0], time);
}
}
if (dp[i][j][score][0] < 1e18) {
if (j - 1 > i) {
int time = dp[i][j][score][0] + x[i] + L - x[j - 1];
ckmin(dp[i][j - 1][score + (time <= t[j - 1])][1], time);
}
if (i + 1 < j) {
int time = dp[i][j][score][0] + x[i + 1] - x[i];
ckmin(dp[i + 1][j][score + (time <= t[i + 1])][0], time);
}
}
}
}
}
int res = 0;
for (int i = 0;i <= n;i++) {
for (int j = n + 1;j > i;j--) {
for (int score = 0;score <= n;score++) {
for (int pos = 0;pos < 2;pos++) {
if (dp[i][j][score][pos] < 1e18) {
if (res < score) res = score;
}
}
}
}
}
cout << res;
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
// agent pengin wants to take apio (with anya-san)
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... |