# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1199531 | thewizardman | Fancy Fence (CEOI20_fancyfence) | C++20 | 5 ms | 328 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n, h[100001], w[100001], dp[100001], md = 1e9+7, ans;
vector<pair<ll, ll>> v;
ll bruh(ll a, ll b) {
return ((a * b) / 2ll) % md;
}
int main() {
scanf("%lld", &n);
for (int i = 0; i < n; i++) scanf("%lld", h+i), h[i]++;
for (int i = 0; i < n; i++) scanf("%lld", w+i), w[i]++;
for (int i = 0; i < n; i++) {
ll consec = 0;
while (!v.empty() && v.back().first > h[i]) consec += v.back().second, v.pop_back();
v.push_back({h[i], consec + w[i]});
ll k = 0, asdf = 0;
for (auto it = v.rbegin(); it != v.rend(); it++) {
auto [h, w] = *it;
ans = (ans + bruh(h, h-1) * bruh(w+k, w-1)) % md;
k += w;
}
}
printf("%lld", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |