/*
Problem Link:https://oj.uz/problem/view/CEOI20_fancyfence
Author: varungoyalbits
*/
#include <bits/stdc++.h>
using namespace std;
long long sumTillN(const long long N,const long long mod)
{
return ((N*(N+1))/2)%mod;
}
long long subTask6()
{
int n;
cin>>n;
vector<long long>h(n);
vector<long long>w(n);
long long mod=1e9+7;
for(int i=0;i<n;i++)
{
cin>>h[i];
}
for(int i=0;i<n;i++)
{
cin>>w[i];
}
long long ans=0;
for(int i=0;i<n;i++)
{
long long val=sumTillN(h[i],mod);
val=(val*sumTillN(w[i],mod))%mod;
ans=(ans+val)%mod;
long long mn=h[i];
for(int j=i-1;j>=0;j--)
{
mn=min(mn,h[j]);
val=sumTillN(mn,mod);
val=(val*((w[i]*w[j])%mod))%mod;
ans=(ans+val)%mod;
}
}
return ans;
}
int main()
{
cout<<subTask6()<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
8 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
268 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
6 ms |
204 KB |
Output is correct |
3 |
Execution timed out |
1088 ms |
1612 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
332 KB |
Output is correct |
2 |
Correct |
462 ms |
620 KB |
Output is correct |
3 |
Execution timed out |
1054 ms |
1956 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
7 ms |
308 KB |
Output is correct |
3 |
Correct |
452 ms |
632 KB |
Output is correct |
4 |
Execution timed out |
1055 ms |
1988 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
6 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
216 KB |
Output is correct |
5 |
Correct |
1 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
6 ms |
204 KB |
Output is correct |
9 |
Correct |
6 ms |
304 KB |
Output is correct |
10 |
Correct |
6 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
204 KB |
Output is correct |
13 |
Correct |
6 ms |
332 KB |
Output is correct |
14 |
Correct |
6 ms |
204 KB |
Output is correct |
15 |
Correct |
6 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
8 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
6 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
6 ms |
204 KB |
Output is correct |
11 |
Execution timed out |
1085 ms |
1604 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |