Submission #577513

# Submission time Handle Problem Language Result Execution time Memory
577513 2022-06-15T03:26:27 Z tengiz05 Fancy Fence (CEOI20_fancyfence) C++17
0 / 100
1 ms 340 KB
#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 time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 328 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 328 KB Output isn't correct
3 Halted 0 ms 0 KB -