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;
#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif
const int md = (int) 1e9 + 7;
void add(int& x, int y) {
x += y;
if (x >= md) {
x -= md;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> b(n);
for (int i = 0; i < n; ++i) {
cin >> b[i];
}
int water = 0;
for (int mask = 0; mask < (1 << n); ++mask) {
vector<int> c(n);
for (int i = 0; i < n; ++i) {
c[i] = (mask >> i & 1 ? b[i] : a[i]);
}
vector<bool> mark(n);
for (int i = 0, mx = 0; i < n; ++i) {
if (c[i] > mx) {
mark[i] = true;
mx = c[i];
}
}
for (int i = n - 1, mx = 0; i >= 0; --i) {
if (c[i] > mx) {
mark[i] = true;
mx = c[i];
}
}
vector<int> d(n);
for (int i = 0; i < n; ++i) {
for (int j = i; j >= 0; --j) {
if (mark[j]) {
d[i] = c[j];
break;
}
}
for (int j = i; j < n; ++j) {
if (mark[j]) {
d[i] = min(d[i], c[j]);
break;
}
}
add(water, d[i] - c[i]);
}
}
cout << water << '\n';
return 0;
}
# | 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... |