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 MOD = 1e9 + 7;
const int TWOINV = 5e8 + 4;
const int MAXN = 1e5 + 25;
int add (int a, int b) {
a += b; if (a >= MOD) a -= MOD;
return a;
}
int sub (int a, int b) {
a -= b; if (a < 0) a += MOD;
return a;
}
int mul (int a, int b) {
return (a * 1ll * b) % MOD;
}
int h[MAXN], w[MAXN], n;
int main () {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> h[i];
for (int i = 1; i <= n; i++) cin >> w[i];
int ans = 0;
for (int i = 1; i <= n; i++) {
int x = w[i], y = h[i];
x = mul(x, mul(x + 1, TWOINV));
y = mul(y, mul(y + 1, TWOINV));
ans = add(ans, mul(x, y));
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
int x = *min_element(h + i, h + j + 1);
x = mul(x, mul(x + 1, TWOINV));
int y = mul(w[i], w[j]);
ans = add(ans, mul(x, y));
}
}
cout << ans << '\n';
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |