Submission #577513

#TimeUsernameProblemLanguageResultExecution timeMemory
577513tengiz05Fancy Fence (CEOI20_fancyfence)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; using i64 = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> h(n + 1), w(n + 1); for (int i = 1; i <= n; i++) { cin >> h[i]; } for (int i = 1; i <= n; i++) { cin >> w[i]; w[i] += w[i - 1]; } vector<int> s{0}; i64 sum = 0; i64 ans = 0; for (int i = 1; i <= n; i++) { while (h[s.back()] > h[i]) { int height = h[s.back()]; int r = w[s.back()]; s.pop_back(); int l = w[s.back()]; sum -= 1LL * (r - l) * (r - l + 1) / 2 * height; sum += 1LL * (r - l) * (r - l + 1) / 2 * h[i]; } ans += sum * (w[i] - w[i - 1]); ans += 1LL * (w[i] - w[i - 1]) * (w[i] - w[i - 1] + 1) / 2 * h[i] * (h[i] + 1) / 2; sum += 1LL * (w[i] - w[i - 1]) * h[i] * (h[i] + 1) / 2; s.push_back(i); } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...