#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000000007;
int MOD(int x) {
return (x+3*mod)%mod;
}
int n, k, m;
vector<int> h, w;
int section(int h, int w) {
h%=mod, w%=mod;
int facteur=MOD((h*(h+1))/2);
int ans=MOD((w*(w+1))/2);
return MOD(ans*facteur);
}
int subtask5() {
int ans=0;
for (int i=0; i<n; i++) {
int mini=h[i];
int sum=w[i];
ans=MOD(ans+section(w[i], h[i]));
for (int j=i+1; j<n; j++) {
mini=min(mini, h[i]);
int res=section(mini, sum);
res-=MOD(section(mini, sum-w[i])+section(mini, sum-w[j]));
res=MOD(res);
res+=section(mini, sum-w[i]-w[j]);
ans=MOD(ans+MOD(res));
}
}
return ans;
}
int solve() {
cin >> n;
h = vector<int>(n), w = vector<int>(n);
for(int i = 0; i < n; i++) cin >> h[i];
for(int i = 0; i < n; i++) cin >> w[i];
return subtask5();
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout << solve() << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
8 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
8 ms |
472 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
348 KB |
Output is correct |
2 |
Correct |
764 ms |
600 KB |
Output is correct |
3 |
Execution timed out |
1025 ms |
2136 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
8 ms |
348 KB |
Output is correct |
3 |
Correct |
758 ms |
604 KB |
Output is correct |
4 |
Execution timed out |
1032 ms |
2132 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
8 ms |
472 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
8 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |