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 md = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
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 res = 0;
for (int mask = 0; mask < (1 << n); mask++) {
vector<int> f;
for (int i = 0; i < n; i++) {
if (mask >> i & 1) {
f.push_back(a[i]);
} else {
f.push_back(b[i]);
}
}
vector<int> L(n);
for (int i = 0; i < n; i++) {
L[i] = max(i == 0 ? 0 : L[i - 1], f[i]);
}
vector<int> R(n);
for (int i = n - 1; i >= 0; i--) {
R[i] = max(i == n - 1 ? 0 : R[i + 1], f[i]);
}
for (int i = 1; i + 1 < n; i++) {
res += max(0, min(L[i - 1], R[i + 1]) - f[i]);
res %= md;
}
}
cout << res << '\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... |