#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int inv = 500000004;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;
int32_t main() {
int n;
cin >> n;
set<int> diff;
vector<int> h(n), w(n);
for(int &x : h) cin >> x, diff.insert(x);
for(int &x : w) cin >> x;
auto f = [&](ll a, ll b) {
ll p1 = 1ll * a * (a + 1) % mod * inv % mod;
ll p2 = 1ll * b * (b + 1) % mod * inv % mod;
return (p1 * p2) % mod;
};
if(diff.size() == 1) {
ll W = 0;
for(int &x : w) W += x, W %= mod;
cout << f(W, h[0]) << '\n';
return 0;
}
ll ans = 0;
for(int i=0; i<n; i++) {
ll W = w[i];
ll H = h[i];
for(int j=i+1; j<n; j++) {
W += w[j];
W %= mod;
H = min(H, 1ll * h[j]);
ll res = (f(W, H) - f(H, (W-w[i]+mod)%mod) + mod - f(H, (W-w[j]+mod)%mod) + mod + f(H, (W-w[i]-w[j]+2*mod)%mod)) % mod;
ans += res;
ans %= mod;
}
}
for(int i=0; i<n; i++) {
ans += f(h[i], w[i]);
ans %= mod;
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
15 ms |
500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
19 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
1085 ms |
1728 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
8 ms |
348 KB |
Output is correct |
3 |
Correct |
28 ms |
1116 KB |
Output is correct |
4 |
Correct |
61 ms |
1992 KB |
Output is correct |
5 |
Correct |
56 ms |
1992 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
6 ms |
592 KB |
Output is correct |
4 |
Correct |
28 ms |
1116 KB |
Output is correct |
5 |
Correct |
69 ms |
1884 KB |
Output is correct |
6 |
Correct |
59 ms |
1884 KB |
Output is correct |
7 |
Correct |
20 ms |
348 KB |
Output is correct |
8 |
Execution timed out |
1088 ms |
1220 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
15 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
15 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
18 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
452 KB |
Output is correct |
13 |
Correct |
15 ms |
516 KB |
Output is correct |
14 |
Correct |
15 ms |
348 KB |
Output is correct |
15 |
Correct |
15 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
15 ms |
500 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
16 ms |
512 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
15 ms |
456 KB |
Output is correct |
11 |
Execution timed out |
1046 ms |
1632 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |