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>
#define int long long
#define fr first
#define sc second
#define pii pair<int,int>
using namespace std;
const int mod = 1e9 + 7;
int modpow(int a, int b){
if(b == 0) return 1;
int res = modpow(a, b / 2);
res = (res * res) % mod;
if(b & 1) res = (res * a) % mod;
return res;
}
int cal(int h, int w){
w = max(0LL, w) % mod;
int res = h * (h + 1) % mod;
res = (res * w) % mod;
res = (res * (w + 1)) % mod;
res = (res * modpow(4, mod - 2)) % mod;
return max(0LL, res);
}
void solve(){
int n;
cin >> n;
vector<int> h(n + 1, 0), w(n + 1, 0);
for(int i = 1; i <= n; ++i) cin >> h[i];
for(int i = 1; i <= n; ++i) cin >> w[i];
vector<vector<int> > min_h(n + 1, vector<int>(n + 1, INT_MAX));
vector<int> pre_w(n + 1, 0);
for(int i = 1; i <= n; ++i){
pre_w[i] = pre_w[i-1] + w[i];
for(int j = i; j <= n; ++j){
min_h[i][j] = min(min_h[i][j-1], h[j]);
}
}
int ans = 0;
for(int i = 1; i <= n; ++i){
for(int j = i; j <= n; ++j){
ans += cal(min_h[i][j], pre_w[j] - pre_w[i-1]);
//cout << ans << ' ';
ans -= cal(min_h[i][j], pre_w[j] - pre_w[i-1] - w[i]);
//cout << ans << ' ';
ans -= cal(min_h[i][j], pre_w[j] - pre_w[i-1] - w[j]);
//cout << ans << ' ';
ans += cal(min_h[i][j], pre_w[j] - pre_w[i-1] - w[j] - w[i]);
ans = (ans + mod) % mod;
//cout << ans << endl;
}
}
cout << ans << endl;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("bbreeds.in", "r");
//freopen("bbreeds.out", "w");
solve();
}
# | 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... |