3082021-08-30 11:09:53Valaki2Fancy Fencecpp14Time limit exceeded 30/1001.095s8788 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted2ms1756 KiB
2Accepted7ms1808 KiB
subtask212/12
3Accepted1ms1868 KiB
4Accepted1ms1872 KiB
5Accepted1ms1872 KiB
6Accepted1ms1884 KiB
7Accepted1ms1884 KiB
subtask30/13
8Accepted6ms1912 KiB
9Time limit exceeded1.054s2312 KiB
10Time limit exceeded1.049s4304 KiB
11Time limit exceeded1.014s5468 KiB
12Time limit exceeded1.019s6640 KiB
subtask40/15
13Accepted6ms6044 KiB
14Accepted509ms6488 KiB
15Time limit exceeded1.008s7028 KiB
16Time limit exceeded1.008s8392 KiB
17Time limit exceeded1.014s8476 KiB
subtask50/15
18Accepted6ms7828 KiB
19Accepted500ms8112 KiB
20Time limit exceeded1.062s7720 KiB
21Time limit exceeded1.095s8488 KiB
22Time limit exceeded1.085s8484 KiB
subtask618/18
23Accepted1ms7812 KiB
24Accepted2ms7828 KiB
25Accepted7ms7832 KiB
26Accepted6ms7832 KiB
27Accepted7ms7832 KiB
subtask70/27
28Accepted505ms8112 KiB
29Accepted500ms8112 KiB
30Time limit exceeded1.093s7716 KiB
31Time limit exceeded1.095s7720 KiB
32Time limit exceeded1.093s8484 KiB
33Time limit exceeded1.095s8420 KiB
34Time limit exceeded1.095s8484 KiB
35Time limit exceeded1.062s8744 KiB
36Accepted1ms7876 KiB
37Time limit exceeded1.093s8740 KiB
38Time limit exceeded1.095s8724 KiB
39Time limit exceeded1.078s8788 KiB
40Time limit exceeded1.093s8724 KiB