308 | 2021-08-30 11:09:53 | Valaki2 | Fancy Fence | cpp14 | Time limit exceeded 30/100 | 1.095s | 8788 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const ll mod = 1e9 + 7;
void solve() {
ll n;
cin >> n;
vector<ll> height(n, 0ll);
vector<ll> width(n, 0ll);
for(ll &x : height) cin >> x;
for(ll &x : width) cin >> x;
ll ans = 0;
for(ll i = 0; i < n; ++i) {
ll cur_height = height[i];
ll temp_height = ((cur_height * (cur_height + 1)) / 2) % mod;
ll temp_width = ((width[i] * (width[i] + 1)) / 2) % mod;
ans += (temp_width * temp_height) % mod;
ans %= mod;
for(ll j = i + 1; j < n; ++j) {
cur_height = min(cur_height, height[j]);
temp_width = (width[i] * width[j]) % mod;
temp_height = ((cur_height * (cur_height + 1)) / 2) % mod;
ans += (temp_width * temp_height) % mod;
ans %= mod;
}
}
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 2ms | 1756 KiB | ||||
2 | Accepted | 7ms | 1808 KiB | ||||
subtask2 | 12/12 | ||||||
3 | Accepted | 1ms | 1868 KiB | ||||
4 | Accepted | 1ms | 1872 KiB | ||||
5 | Accepted | 1ms | 1872 KiB | ||||
6 | Accepted | 1ms | 1884 KiB | ||||
7 | Accepted | 1ms | 1884 KiB | ||||
subtask3 | 0/13 | ||||||
8 | Accepted | 6ms | 1912 KiB | ||||
9 | Time limit exceeded | 1.054s | 2312 KiB | ||||
10 | Time limit exceeded | 1.049s | 4304 KiB | ||||
11 | Time limit exceeded | 1.014s | 5468 KiB | ||||
12 | Time limit exceeded | 1.019s | 6640 KiB | ||||
subtask4 | 0/15 | ||||||
13 | Accepted | 6ms | 6044 KiB | ||||
14 | Accepted | 509ms | 6488 KiB | ||||
15 | Time limit exceeded | 1.008s | 7028 KiB | ||||
16 | Time limit exceeded | 1.008s | 8392 KiB | ||||
17 | Time limit exceeded | 1.014s | 8476 KiB | ||||
subtask5 | 0/15 | ||||||
18 | Accepted | 6ms | 7828 KiB | ||||
19 | Accepted | 500ms | 8112 KiB | ||||
20 | Time limit exceeded | 1.062s | 7720 KiB | ||||
21 | Time limit exceeded | 1.095s | 8488 KiB | ||||
22 | Time limit exceeded | 1.085s | 8484 KiB | ||||
subtask6 | 18/18 | ||||||
23 | Accepted | 1ms | 7812 KiB | ||||
24 | Accepted | 2ms | 7828 KiB | ||||
25 | Accepted | 7ms | 7832 KiB | ||||
26 | Accepted | 6ms | 7832 KiB | ||||
27 | Accepted | 7ms | 7832 KiB | ||||
subtask7 | 0/27 | ||||||
28 | Accepted | 505ms | 8112 KiB | ||||
29 | Accepted | 500ms | 8112 KiB | ||||
30 | Time limit exceeded | 1.093s | 7716 KiB | ||||
31 | Time limit exceeded | 1.095s | 7720 KiB | ||||
32 | Time limit exceeded | 1.093s | 8484 KiB | ||||
33 | Time limit exceeded | 1.095s | 8420 KiB | ||||
34 | Time limit exceeded | 1.095s | 8484 KiB | ||||
35 | Time limit exceeded | 1.062s | 8744 KiB | ||||
36 | Accepted | 1ms | 7876 KiB | ||||
37 | Time limit exceeded | 1.093s | 8740 KiB | ||||
38 | Time limit exceeded | 1.095s | 8724 KiB | ||||
39 | Time limit exceeded | 1.078s | 8788 KiB | ||||
40 | Time limit exceeded | 1.093s | 8724 KiB |