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 vi vector<int>
#define vll vector<long long int>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<long long int, long long int>>
#define pb push_back
#define f0r(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll mod = 1e9 + 7;
ll ans(ll w, ll h){
return w * (w+1)/2 % mod * h * (h+1)/2 % mod;
}
ll c2(ll x){
return x * (x+1) / 2 % mod;
}
int main(){
int n;
cin>>n;
vll w(n);
vll h(n);
f0r(i,n)cin>>h[i];
f0r(i,n)cin>>w[i];
ll dp[n+1];
dp[0] = ans(w[0], h[0]);
for(int i = 1;i<n;i++){
dp[i] = ((dp[i-1] + ans(w[i], h[i])) % mod + (w[i-1] * w[i] % mod * c2(min(h[i-1], h[i])) % mod)) % mod;
}
cout<<dp[n-1];
}
# | 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... |