답안 #1106020

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106020 2024-10-28T21:44:46 Z LaviniaTornaghi Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
18 ms 3920 KB
#include <bits/stdc++.h>
using namespace std;

constexpr int MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int N; cin >> N;

    vector<int> H(N), W(N);
    for (auto &h: H) cin >> h;
    for (auto &w: W) cin >> w;

    vector<int> ps(N + 1);
    for (int i = 0; i < N; i++) ps[i + 1] = (ps[i] + W[i]) % MOD;

    int ans = 0;
    stack<int> st;
    for (int i = 0; i < N; i++) {
        while (!st.empty() && H[st.top()] >= H[i]) {
            int lst = st.top(); st.pop();

            int max_h = H[lst];
            int min_h = max(H[i], st.empty() ? 0 : H[st.top()]);
            int dw = (ps[i] - (st.empty() ? 0 : ps[st.top() + 1]) + MOD) % MOD;

            int wc = ((long long)dw * (dw + 1) / 2) % MOD;
            int hc = ((long long)max_h * (max_h + 1) / 2 - (long long)min_h * (min_h + 1) / 2) % MOD;
            int ch = (long long)wc * hc % MOD;

            ans = (ans + ch) % MOD;
        }

        st.push(i);
    }

    while (!st.empty()) {
        int lst = st.top(); st.pop();

        int max_h = H[lst];
        int min_h = st.empty() ? 0 : H[st.top()];
        int dw = (ps.back() - (st.empty() ? 0 : ps[st.top() + 1]) + MOD) % MOD;

        int wc = ((long long)dw * (dw + 1) / 2) % MOD;
        int hc = ((long long)max_h * (max_h + 1) / 2 - (long long)min_h * (min_h + 1) / 2) % MOD;
        int ch = (long long)wc * hc % MOD;

        ans = (ans + ch) % MOD;
    }

    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 8 ms 1784 KB Output is correct
4 Correct 13 ms 2760 KB Output is correct
5 Correct 13 ms 2640 KB Output is correct
6 Correct 16 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 9 ms 1872 KB Output is correct
4 Correct 17 ms 3532 KB Output is correct
5 Correct 17 ms 3664 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 3 ms 592 KB Output is correct
4 Correct 13 ms 1872 KB Output is correct
5 Correct 18 ms 3444 KB Output is correct
6 Correct 18 ms 3536 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 2 ms 728 KB Output is correct
9 Correct 9 ms 2128 KB Output is correct
10 Correct 17 ms 3820 KB Output is correct
11 Correct 17 ms 3920 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 7 ms 1616 KB Output is correct
12 Correct 14 ms 2640 KB Output is correct
13 Correct 14 ms 2640 KB Output is correct
14 Correct 13 ms 2640 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 8 ms 1988 KB Output is correct
18 Correct 16 ms 3408 KB Output is correct
19 Correct 17 ms 3532 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 9 ms 2128 KB Output is correct
23 Correct 15 ms 3828 KB Output is correct
24 Correct 17 ms 3920 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 3 ms 652 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 8 ms 1736 KB Output is correct
33 Correct 11 ms 1880 KB Output is correct
34 Correct 16 ms 3152 KB Output is correct
35 Correct 16 ms 3152 KB Output is correct
36 Correct 16 ms 3408 KB Output is correct
37 Correct 16 ms 3408 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 16 ms 3552 KB Output is correct
40 Correct 16 ms 3404 KB Output is correct
41 Correct 17 ms 3420 KB Output is correct
42 Correct 17 ms 3664 KB Output is correct