Submission #963006

# Submission time Handle Problem Language Result Execution time Memory
963006 2024-04-14T10:55:33 Z zwezdinv Fancy Fence (CEOI20_fancyfence) C++17
15 / 100
29 ms 3288 KB
#include<bits/stdc++.h>
using namespace std;

using ll = long long;

int mod = 1e9 + 7;
int add(int a, int b) {
    return a + b >= mod ? a + b - mod : a + b;
}
int sub(int a, int b) {
    return a >= b ? a - b : a + mod - b;
}
int mul(int a, int b) {
    return 1ll * a * b % mod;
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int i2 = (mod + 1) / 2;
    auto sshit = [&](int x) -> int {
        return mul(mul(x, x + 1), i2);
    };

    int n;
    cin >> n;
    vector<pair<int, int>> st;
    vector<int> h(n), w(n);
    for (auto& i : h) cin >> i;
    for (auto& i : w) cin >> i;
    int sum = 0;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int cnt = w[i];
        while (st.size() && st.back().first >= w[i]) {
            cnt = add(cnt, st.back().second);
            sum = sub(sum, mul(sshit(st.back().first), st.back().second));
            st.pop_back();
        }
        st.emplace_back(h[i], cnt);
        sum = add(sum, mul(sshit(h[i]), cnt));
        int cur = mul(sum, w[i]);
        cur = sub(cur, mul(sshit(h[i]), mul(w[i], w[i])));
        cur = add(cur, mul(sshit(w[i]), sshit(h[i])));
        ans = add(ans, cur);
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 3 ms 736 KB Output is correct
3 Correct 13 ms 1636 KB Output is correct
4 Correct 26 ms 3160 KB Output is correct
5 Correct 29 ms 3156 KB Output is correct
6 Correct 0 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 13 ms 1628 KB Output is correct
5 Correct 26 ms 3160 KB Output is correct
6 Correct 28 ms 3288 KB Output is correct
7 Incorrect 1 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 352 KB Output is correct
2 Incorrect 1 ms 352 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -