# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1088113 | Zero_OP | Collecting Stamps 3 (JOI20_ho_t3) | C++14 | 110 ms | 135544 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;
#define sz(v) (int)v.size()
#define all(v) begin(v), end(v)
#define compact(v) v.erase(unique(all(v)), end(v))
#define dbg(v) "[" #v " = " << (v) << "]"
#define file(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define rep(i, l, r) for(int i = (l); i < (r); ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using ld = long double;
template<typename T>
bool minimize(T& a, const T& b){
if(a > b){
return a = b, true;
} return false;
}
template<typename T>
bool maximize(T& a, const T& b){
if(a < b){
return a = b, true;
} return false;
}
template<int dimension, typename T>
struct tensor : public vector<tensor<dimension - 1, T>> {
static_assert(dimension > 0, "Dimension must be positive !\n");
template<typename... Args>
tensor(int n = 0, Args... args) : vector<tensor<dimension - 1, T>> (n, tensor<dimension - 1, T>(args...)) {}
};
template<typename T>
struct tensor<1, T> : public vector<T> {
tensor(int n = 0, T val = T()) : vector<T>(n, val) {}
};
const int MAX = 200 + 5;
int N, L, X[MAX], T[MAX];
ll dp[MAX][MAX][MAX][2];
//dp[k][i][j][atR]
void testcase(){
cin >> N >> L;
for(int i = 1; i <= N; ++i){
cin >> X[i];
}
for(int i = 1; i <= N; ++i){
cin >> T[i];
}
X[N + 1] = L;
T[N + 1] = 1e9 + 8;
memset(dp, 0x3f, sizeof(dp));
ll inf = dp[0][0][0][0];
dp[0][0][N + 1][0] = 0;
dp[0][0][N + 1][1] = 0;
for(int i = 0; i < N; ++i){
for(int j = N + 1; j >= i + 2; --j){
for(int k = 0; k <= N; ++k){
ll cost = min(dp[k][i][j][0] + X[i + 1] - X[i], dp[k][i][j][1] + L - (X[j] - X[i + 1]));
minimize(dp[k + (cost <= T[i + 1])][i + 1][j][0], cost);
cost = min(dp[k][i][j][0] + L - (X[j - 1] - X[i]), dp[k][i][j][1] + (X[j] - X[j - 1]));
minimize(dp[k + (cost <= T[j - 1])][i][j - 1][1], cost);
}
}
}
// for(int k = 0; k <= N; ++k){
// for(int i = 0; i <= N + 1; ++i){
// for(int j = i + 2; j <= N + 1; ++j){
// for(int atR = 0; atR < 2; ++atR){
// cout << dbg(k) << dbg(i) << dbg(j) << dbg(atR) << dbg(dp[k][i][j][atR]) << '\n';
// }
// }
// }
// }
for(int k = N; k >= 1; --k){
for(int i = 0; i <= N + 1; ++i){
for(int j = 0; j <= N + 1; ++j){
for(int atR = 0; atR < 2; ++atR){
if(dp[k][i][j][atR] < inf){
cout << k << '\n';
return;
}
}
}
}
}
cout << 0 << '\n';
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
file("task");
int T = 1;
// cin >> T;
while(T--){
testcase();
}
return 0;
}
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... |