#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 10;
int r[N][3];
int w[N];
int h[N];
int mod = 1e9 + 7;
int power(int a,int b){
if (b==0)
return 1;
int ans = power(a,b/2);
ans = ans*ans;
ans %= mod;
if (b%2)
ans = ans*a;
return ans%mod;
}
int mod_inv(int k){
return power(k,mod-2);
}
int asd(int a){
int ans = (a*(a+1));
ans = ans%mod;
ans = ans*mod_inv(2);
ans = ans% mod;
return ans;
}
signed main(){
int n;
cin>>n;
for (int i=1;i<=n;i++)
cin>>h[i];
int ans = 0;
for (int i=1;i<=n;i++){
cin>>w[i];
ans += w[i];
ans %= mod;
}
ans = asd(ans);
int ans2 = asd(h[1]);
cout<<(ans*ans2)%mod<<endl;
return 0;
for (int i=n;i>=1;i--){
for (int j=1;j<=h[i];j++){
r[i][j] = r[i+1][j];
ans += (r[i][j]*j)%mod;
ans %= mod;
r[i][j] += w[i];
r[i][j] %= mod;
// cout<<"At "<<i<<" "<<j<<" added "<<r[i][j]*j<<endl;
}
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2548 KB |
Output is correct |
2 |
Correct |
6 ms |
2652 KB |
Output is correct |
3 |
Correct |
28 ms |
3396 KB |
Output is correct |
4 |
Correct |
55 ms |
4552 KB |
Output is correct |
5 |
Correct |
57 ms |
4696 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |