# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1106919 | duckindog | Flooding Wall (BOI24_wall) | C++17 | 192 ms | 2640 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;
const int N = 500'000 + 10,
M = 1'000'000'007;
int n;
int a[N], b[N];
void add(auto& x, const auto& y) {
x += y;
if (x >= M) x -= M;
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) cin >> b[i];
long long answer = 0;
for (int mask = 0; mask < (1 << n); ++mask) {
vector<int> fwd(n + 2), bwd(n + 2);
for (int i = 1; i <= n; ++i)
fwd[i] = max(fwd[i - 1], (mask >> (i - 1) & 1) ? a[i] : b[i]);
for (int i = n; i >= 1; --i)
bwd[i] = max(bwd[i + 1], (mask >> (i - 1) & 1) ? a[i] : b[i]);
for (int i = 1; i <= n; ++i) {
int height = ((mask >> (i - 1) & 1) ? a[i] : b[i]);
int mi = min(fwd[i - 1], bwd[i + 1]);
if (mi > height) add(answer, mi - height);
}
}
cout << answer << "\n";
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |